HDU1715:大菲波数
求第i个斐波那契数问题(与HDU1316类似,但更简单):
总结:
数组开多大?题目中让求的最大的是第1000个斐波那契数是多少,由于f[0]不用,所以数组开到1001。
import java.util.Scanner;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
BigInteger f[] = new BigInteger[1001];
int T = in.nextInt();
f[1] = new BigInteger("1");
f[2] = new BigInteger("1");
for (int i = 3; i < f.length; i++) {
f[i] = f[i - 1].add(f[i - 2]);
}
while (T != 0) {
int a = in.nextInt();
System.out.println(f[a]);
T--;
}
}
}