首页 > 其他 > 详细

大数快速开方

时间:2015-05-19 10:50:03      阅读:242      评论:0      收藏:0      [点我收藏+]

大数快速开方!


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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!