标签:大数开方
大数快速开方!
import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); BigInteger N = sc.nextBigInteger(); System.out.println(sqrt(N)); } public static BigInteger sqrt(BigInteger input) { BigInteger x0 = BigInteger.TEN.pow((int)Math.sqrt(input.toString().length())); BigInteger x1 = BigInteger.valueOf(11); while(!x0.equals(x1) && !x0.equals(x1.add(BigInteger.ONE))) { x0 = new BigInteger(x1.toString()); x1 = x1.add(input.divide(x1)).divide(new BigInteger("2")); } return x1; } }
标签:大数开方
原文地址:http://blog.csdn.net/first_sight/article/details/45827559