111原题链接http://acm.sgu.ru/problem.php?contest=0&problem=111
112原题链接http://acm.sgu.ru/problem.php?contest=0&problem=112
这里我超级偷懒,用了 JAVA的大数类~~~
sgu111,二分查找
import java.io.*;
import java.math.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
BigInteger l = new BigInteger("1");
BigInteger r = (new BigInteger("10")).pow(500);
BigInteger one = new BigInteger("1");
Scanner cin = new Scanner(new BufferedInputStream(System.in));
BigInteger x = cin.nextBigInteger();
BigInteger mid,ans;
ans = new BigInteger("1");
while(true){
mid = (l.add(r)).shiftRight(1);
if( (mid.pow(2)).compareTo(x) > 0){
r = mid.subtract(one);
}else{
ans = mid;
l = mid.add(one);
}
if(l.compareTo(r) > 0)
break;
}
System.out.println(ans);
}
}
sgu112
import java.io.*;
import java.math.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner cin = new Scanner(new BufferedInputStream(System.in));
int x = cin.nextInt();
int y = cin.nextInt();
BigInteger bigx = BigInteger.valueOf(x);
BigInteger bigy = BigInteger.valueOf(y);
BigInteger result = bigx.pow(y).subtract(bigy.pow(x));
System.out.println(result);
}
}