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

版权声明:https://github.com/godspeedcurry 欢迎加好友哦 https://blog.csdn.net/qq_38677814/article/details/82743607
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");
				} 
			}
		}
	}
}

猜你喜欢

转载自blog.csdn.net/qq_38677814/article/details/82743607