大数操作模板
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
static PrintWriter cout = new PrintWriter(new OutputStreamWriter(System.out),true);
static final int maxn=200003;
static final int INF=1000000007;
static BigInteger[] h = new BigInteger[maxn];
static BigInteger[] b = new BigInteger[maxn];
static BigInteger[] a = new BigInteger[maxn];
static BigInteger[] c = new BigInteger[maxn], d = new BigInteger[maxn];
static BigDecimal ffk = new BigDecimal("6.430703308172535824813264335274");
static BigInteger g(int x){
return BigInteger.valueOf(x);
}
static BigInteger g(int x,BigInteger y){
return y.multiply(g(x));
}
static BigInteger g(int x,BigInteger y,BigInteger z){
return z.multiply(y.multiply(g(x)));
}
public static void main(String[] args) {
h[0] = g(2);
h[1] = g(3);
h[2] = g(6);
c[1] = g(9);
c[2] = g(15);
int n = 20;
for (int i = 3; i <= n; i += 1){
h[i]=g(4,h[i-1]).add(g(17,h[i-2])).subtract(g(12,h[i-3]));
h[i]=h[i].subtract(g(16));
}
for (int i = 1; i < n; i += 1){
b[i]=g(3,h[i+1],h[i]).add(g(9,h[i+1],h[i-1])).add(g(9,h[i],h[i])).add(g(27,h[i],h[i-1])).subtract(g(18,h[i+1])).subtract(g(126,h[i])).subtract(g(81,h[i-1])).add(g(192));
}
for (int i = 2; i < n; i += 1){
a[i]=b[i].add(g(4).pow(i));
a[i]=myBigNumSqrt(a[i]);
if(i>=10){
BigInteger x = g(4,a[i-1]).add(g(17,a[i-2])).add(g(-12,a[i-3]));
cout.println(i+ " "+ a[i] + " " + x);
}else cout.println(i+ " "+ a[i]);
cout.println(a[i].mod(g(INF)));
}
cout.println("");
}
public static BigInteger myBigNumSqrt(BigInteger xx){
BigDecimal x=new BigDecimal(xx);
BigDecimal n1=BigDecimal.ONE;
BigDecimal ans=BigDecimal.ZERO;
while((n1.multiply(n1).subtract(x)).abs().compareTo(BigDecimal.valueOf(0.001))==1)
{
BigDecimal s1=x.divide(n1,2000,RoundingMode.HALF_UP);
BigDecimal s2=n1.add(s1);
n1=s2.divide(BigDecimal.valueOf(2),2000,RoundingMode.HALF_UP);
}
ans=n1;
BigInteger rt =new BigInteger(ans.toString().split("\\.")[0]);
return rt;
}
}