import java.math.BigInteger;
import java.util.*;
public class Main
{
public static BigInteger sqrt(BigInteger num){
if(num.compareTo(new BigInteger("1"))==0)return num;
BigInteger p=new BigInteger("0");
BigInteger q=num;
while(p.compareTo(q)<0){
BigInteger mid=p.add(q).divide(new BigInteger("2"));
if(mid.multiply(mid).compareTo(num)==0)return mid;
else if(mid.multiply(mid).compareTo(num)>0)q=mid;
else if(p.compareTo(mid)!=0){
p=mid;
}
else break;
}
return p;
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
BigInteger num=sc.nextBigInteger();
System.out.println(sqrt(num));
}
}
大整数开方
最新推荐文章于 2021-01-18 11:10:29 发布