Square root
The Problem
You are to determinate X by given Y, from expression
The Input
The first line is the number of test cases, followed by a blank line.
Each test case of the input contains a positive integer Y (1<=Y<=101000), with no blanks or leading zeroes in it.
It is guaranteed, that for given Y, X will be always an integer.
Each test case will be separated by a single line.
The Output
For each test case, your program should print X in the same format as Y was given in input.
Print a blank line between the outputs for two consecutive test cases.
Sample Input
1 7206604678144
Sample Output
2684512
题意:大数开方。
思路:算作是一个模板收藏吧。
AC代码如下:
import java.math.BigInteger;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
BigInteger n,temp,y;
BigInteger TWO=new BigInteger("2");
int T,t,i,j,k;
T=scan.nextInt();
for(t=1;t<=T;t++)
{
n=scan.nextBigInteger();
y=n;
do {
temp = y;
y = temp.add(n.divide(y)).divide(TWO);
}
while (y.compareTo(temp) == -1);
if(t!=1)
System.out.println();
System.out.println(y);
}
}
}