标签:16px 计算 main com out 答案 class ann rgs
目录
具体代码如下:
import java.math.BigInteger; import java.util.Scanner; public class Main { public static BigInteger getSqrt(String A) { String sqrt = "0"; String pre = "0"; BigInteger twenty = new BigInteger("20"); BigInteger temp1 = BigInteger.ZERO; BigInteger temp2 = BigInteger.ZERO; int len = A.length(); if(len % 2 == 1) { A = "0" + A; len = len + 1; } for(int i = 0;i < len / 2;i++) { BigInteger tempN = new BigInteger(pre + A.substring(i*2, i*2 + 2)); for(int j = 0;j <= 9;j++) { BigInteger tempJ = new BigInteger(j+""); temp1 = twenty.multiply(new BigInteger(sqrt)).add(tempJ).multiply(tempJ); tempJ = tempJ.add(BigInteger.ONE); temp2 = twenty.multiply(new BigInteger(sqrt)).add(tempJ).multiply(tempJ); if(temp1.compareTo(tempN) <= 0 && temp2.compareTo(tempN) > 0) { sqrt = sqrt + j; pre = tempN.subtract(temp1).toString(); break; } } } return new BigInteger(sqrt); } public static void main(String[] args) { Scanner in = new Scanner(System.in); String n = in.next(); String m = in.next(); BigInteger result = getSqrt(n).multiply(getSqrt(m)); System.out.println(result); } }
标签:16px 计算 main com out 答案 class ann rgs
原文地址:http://www.cnblogs.com/liuzhen1995/p/6797549.html