Java代码:适合被开方数不超过1000位的。
import java.util.*;
import java.math.*;
public class Main
{
public static void main(String[] args)
{
Scanner cin=new Scanner(System.in);
int t=cin.nextInt();
BigInteger remain=BigInteger.ZERO;
BigInteger odd=BigInteger.ZERO;
BigInteger ans=BigInteger.ZERO;
for(int i=0;i
{
String s=cin.next();
remain=BigInteger.ZERO;
odd=BigInteger.ZERO;
ans=BigInteger.ZERO;
int group=0,k=0;
if(s.length()%2==1)
{
group=s.charAt(0)-'0';
k=-1;
}
else
{
group=(s.charAt(0)-'0')*10+s.charAt(1)-'0';
k=0;
}
for(int j=0;j
{
if(j!=0)
group=(s.charAt(j*2+k)-'0')*10+s.charAt(j*2+k+1)-'0';
odd=BigInteger.valueOf(20).multiply(ans).add(BigInteger.ONE);
remain=BigInteger.valueOf(100).multiply(remain).add(BigInteger.valueOf(group));
int count=0;
while(remain.compareTo(odd)>=0)
{
count++;
remain=remain.subtract(odd);
odd=odd.add(BigInteger.valueOf(2));
}
ans=ans.multiply(BigInteger.TEN).add(BigInteger.valueOf(count));
}
System.out.println(ans);
if(i!=t-1) System.out.println();
}
}
}