Participate in E-sports java处理ACM中的大整数问题

1 篇文章 0 订阅
import java.io.*;
import java.util.*;
// import java.util.Scanner;
import java.math.*;
public class Main{
	static boolean judge(BigInteger x){
		if(x.equals(BigInteger.ZERO)) return true;
		BigInteger two=BigInteger.valueOf(2);
		BigInteger low=BigInteger.ONE,high=x,mid;
		while(low.compareTo(high)<=0){
			mid=low.add(high).shiftRight(1);//比divide快
			BigInteger tmp=mid.multiply(mid);
			if(tmp.equals(x)) return true;
			if(tmp.compareTo(x)>0){
				high=mid.subtract(BigInteger.ONE);
			}
			if(tmp.compareTo(x)<0){
				low=mid.add(BigInteger.ONE);
			}
		}
		return false;
	}
	public static void main (String[] args){
		Scanner sc =new Scanner(System.in);
		while(sc.hasNext()){
			int nn = sc.nextInt();
			for(int i=0;i<nn;i++){
				BigInteger n = sc.nextBigInteger() ;
				BigInteger b = new BigInteger("2");
				boolean flag1=judge(n);
				boolean flag2=judge(n.multiply(n.subtract(BigInteger.ONE) ).shiftRight(1));
				if(flag1&&flag2){
					System.out.println("Arena of Valor");
				}
				else if(flag2){
					System.out.println("Clash Royale");
				}
				else if(flag1){
					System.out.println("Hearth Stone");
				}
				else{
					System.out.println("League of Legends");
				} 
			}
		}
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值