-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBigExp.java
56 lines (54 loc) · 1.18 KB
/
BigExp.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Scanner;
public class BigExp {
public static void main(String[] args) {
int input = 0 ;
Scanner scan =new Scanner(System.in);
input = scan.nextInt();
int [][]arr =new int[input][2];
for(int row=0;row<input;row++){
for(int column=0;column<2;column++){
arr[row][column] = scan.nextInt();
}
}
for(int temp=0;temp<input;temp++){
String tempr=big(arr[temp][0]).toString();
String tempc=big(arr[temp][1]).toString();
BigInteger a=new BigInteger(tempr);
BigInteger b=new BigInteger(tempc);
BigInteger c=a.add(b);
System.out.print(c.toString()+"\r\n");
}
}
public static StringBuffer big(int n){
final int size=2000;
int res[]=new int[size+1];
int i;
for( i = 0;i < size;++ i){
res[i] = 0;
}
res[0] = 1;
while(n > 0){
for(i = 0;i < size;++ i){
res[i] *= 2;
}
for(i = 0;i < size;++ i){
if(res[i] > 9){
res[i + 1] += res[i] / 10;
res[i] %= 10;
}
}
n --;
}
boolean bl = false;
StringBuffer bf = new StringBuffer();
for(i = size;i >= 0;-- i){
if(res[i] != 0 || bl){
bf.append(res[i]);
bl = true;
}
}
return bf;
}
}