加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

sgu111-112大数运算

发布时间:2020-12-14 03:35:58 所属栏目:大数据 来源:网络整理
导读:111原题链接http://acm.sgu.ru/problem.php?contest=0problem=111 112原题链接http://acm.sgu.ru/problem.php?contest=0problem=112 这里我超级偷懒,用了 JAVA的大数类~~~ sgu111,二分查找 import java.io.*;import java.math.*;import java.util.*;publ

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);
	}
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读