POJ1205
递推公式为a[i] = 3*a[i-1] - a[i-2], a[1] = 1,a[2] = 3 , i 最高为100;
搞懂了使用BigInteger开数组。
import java.util.*;
import java.math.*; public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
BigInteger a[] = new BigInteger[101];
a[1] = BigInteger.ONE;
a[2] = BigInteger.valueOf(3);
BigInteger Three = BigInteger.valueOf(3);
for(int i=3; i<=100; i++)
a[i] = Three.multiply(a[i-1]).subtract(a[i-2]);
while(cin.hasNext())
{
int n = cin.nextInt();
System.out.println(a[n]);
}
}
}