//http://acm.pku.edu.cn/JudgeOnline/problem?id=2109
import java.math.*;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
BigInteger L=new BigInteger("1");
BigInteger R=new BigInteger("1000000000");
Scanner s = new Scanner(System.in);
while(s.hasNext())
{
int n=s.nextInt();
BigInteger p=s.nextBigInteger();
BigInteger l=L,r=R;
BigInteger ans=BigInteger.valueOf(-1);
while(l.compareTo(r)<=0)
{
BigInteger k=(l.add(r)).divide(BigInteger.valueOf(2));
BigInteger temp=k.pow(n);
if(p.compareTo(temp)==0)
{
ans=k;
break;
}
else if(p.compareTo(temp)>0)
{
l=k.add(BigInteger.ONE);
if(ans.compareTo(k)<0)ans=k;
}
else
{
r=k.subtract(BigInteger.ONE);
}
}
System.out.println(ans);
}
}
}
poj 2109 大数+二分搜索
最新推荐文章于 2019-02-17 16:54:54 发布