SGU111 Very simple problem

多少个平方数小于等于X,二分。

PS:java BigInteger

import java.util.*;

import java.math.*;



public class Solution {

    public static void main(String args[]) {

        Scanner in = new Scanner(System.in);



        BigInteger X = in.nextBigInteger();



        BigInteger L = BigInteger.valueOf(1);

        BigInteger R = BigInteger.valueOf(10).pow(500);



        while (L.compareTo(R) <= 0) {

            BigInteger M = L.add(R).divide(BigInteger.valueOf(2));

            if (M.pow(2).compareTo(X) <= 0) {

                L = M.add(BigInteger.valueOf(1));

            } else {

                R = M.subtract(BigInteger.valueOf(1));

            }

        }



        System.out.println(R);

    }

}

 

你可能感兴趣的:(simple)