SGU111 Very simple problem

it2022-05-09  37

多少个平方数小于等于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); } }

 

转载于:https://www.cnblogs.com/litstrong/p/3252691.html

相关资源:数据结构—成绩单生成器

最新回复(0)