Wednesday 2 June 2021

Solving a BigInteger problem UVA 10523 - Very Easy !!!

Problem link

This is a straightforward problem of of java BigInteger . Learn it frome here .

Code:

 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.math.BigInteger;
import java.util.Scanner;
public class Main{

	public static void main(String[] args){
		Scanner scn = new Scanner(System.in);
		BigInteger tot,temp;
		int n,a;
		while(scn.hasNextInt()){
			n=scn.nextInt();
			a=scn.nextInt();

			tot=new BigInteger("0");
			temp=BigInteger.valueOf(a);

			for(int i=1;i<=n;i++){
				tot=tot.add(BigInteger.valueOf(i).multiply(temp.pow(i)));
			}
			System.out.println(tot);
		} 
	}
}

Monkey Banana Problem lightoj 1004

  In this problem we will check which adjacent cell will benefits the monkey best. For this, we will check all possible solution of this pro...