题意:求有多少个数的平方不大于大数N;1≤N≤101000
分析:java大数二分
import java.util.Scanner; import java.math.*; public class Solution { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner cin=new Scanner(System.in); BigInteger bb; while(cin.hasNextBigInteger()){ bb=cin.nextBigInteger(); BigInteger L=BigInteger.valueOf(1); BigInteger R=BigInteger.valueOf(10); R=R.pow(500); while(L.compareTo(R)<0){ //System.out.println("L "+L); //System.out.println("R "+R); BigInteger m=L.add(R.subtract(L).add(BigInteger.valueOf(1)).shiftRight(1)); //System.out.println("m "+m); if(m.pow(2).compareTo(bb)<=0){ L=m; } else{ R=m.subtract(BigInteger.valueOf(1)); } } System.out.println(L); } } }