您的位置:首页 > 其它

sgu111-112大数运算

2014-05-09 16:10 267 查看
111原题链接http://acm.sgu.ru/problem.php?contest=0&problem=111

112原题链接http://acm.sgu.ru/problem.php?contest=0&problem=112

这里我超级偷懒,用了 J***A的大数类~~~

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);
	}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: