题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6222
解析:规律:a[n] = 4*a[n-1] - a[n-2]
代码:
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static Scanner s = new Scanner(System.in);
public static void main(String args[]) throws Exception {
int t;
t = s.nextInt();
while(t-- != 0)
{
BigInteger x = s.nextBigInteger();
BigInteger p = new BigInteger("4"), pp = new BigInteger("2"), k = new BigInteger("4");
BigInteger now = p;
while(now.compareTo(x) < 0)
{
now = p.multiply(k).subtract(pp);
pp = p;
p = now;
}
System.out.println(now);
}
}
}