ACM-ICPC 2018 焦作赛区网络预赛 J Participate in E-sports(大数开方)

时间:2023-03-09 19:03:23
ACM-ICPC 2018 焦作赛区网络预赛 J Participate in E-sports(大数开方)

https://nanti.jisuanke.com/t/31719

题意

让你分别判断n或(n-1)*n/2是否是完全平方数

分析

二分高精度开根裸题呀。经典题:bzoj1213

用java套个板子求出平方根,再乘回来检验一下就好。

import java.util.*;
import java.math.*;
public class Main{
static BigInteger check(BigInteger n,BigInteger x) {
BigInteger ans=BigInteger.valueOf();
BigInteger a=BigInteger.valueOf();
for(BigInteger i=BigInteger.ZERO;i.compareTo(n)<;i=i.add(a)) {
ans=ans.multiply(x);
}
return ans;
}
static BigInteger Get(BigInteger n,BigInteger m) {//大数m开n次根
BigInteger l=BigInteger.ZERO;
BigInteger a=BigInteger.valueOf();
BigInteger b=BigInteger.valueOf();
BigInteger r=BigInteger.valueOf();
BigInteger mid=BigInteger.ZERO;
while(check(n,r).compareTo(m)<=) {
l=r;
r=r.multiply(a);
}
while(l.compareTo(r)<=) {
mid=l.add(r).divide(a);
if(check(n,mid).compareTo(m)<=) l=mid.add(b);
else r=mid.subtract(b);
}
return r;
}
public static void main(String[]args) {
int t;
Scanner sca=new Scanner(System.in);
t=sca.nextInt();
BigInteger m=new BigInteger("");
while(t--!=){
BigInteger n1=sca.nextBigInteger();
BigInteger n2=n1.multiply(n1.subtract(BigInteger.ONE)).divide(m);
BigInteger res1=Get(m,n1);
BigInteger res2=Get(m,n2);
boolean f1=false,f2=false;
if(res1.multiply(res1).compareTo(n1)==) f1=true;
if(res2.multiply(res2).compareTo(n2)==) f2=true;
if(f1&&f2){
System.out.println("Arena of Valor");
}else if(f1){
System.out.println("Hearth Stone");
}else if(f2){
System.out.println("* Royale");
}else{
System.out.println("League of Legends");
} }
}
}