Problem Description
Fibonacci数列,定义如下:
f(1)=f(2)=1
f(n)=f(n-1)+f(n-2) n>=3。
计算第n项Fibonacci数值。
f(1)=f(2)=1
f(n)=f(n-1)+f(n-2) n>=3。
计算第n项Fibonacci数值。
Input
输入第一行为一个整数N,接下来N行为整数Pi(1<=Pi<=1000)。
Output
输出为N行,每行为对应的f(Pi)。
Sample Input
5 1 2 3 4 5
Sample Output
1 1 2 3 5import java.util.*; import java.math.*; import java.io.*; import java.text.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); BigInteger []x = new BigInteger [1024]; x[1] = x[2] = BigInteger.ONE; for(int i = 3; i < 1024; i++) x[i] = x[i-1].add(x[i-2]); int n, N = cin.nextInt(); for(n = 1; n <= N; n++){ int t = cin.nextInt(); System.out.println(x[t].toString()); } } }