大菲波数
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13049 Accepted Submission(s): 4499
Total Submission(s): 13049 Accepted Submission(s): 4499
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 5
Source
Recommend
lcy | We have carefully selected several similar problems for you: 1063 1047 1133 2100 1316
/*
* http://acm.hdu.edu.cn/showproblem.php?pid=1715
* by jtahstu on 2015/3/31 14:00
*/
package 大数;
import java.math.BigInteger;
import java.util.Scanner;
public class HDU1715 {
public static Scanner cin=new Scanner(System.in);
public static void main(String[] args) {
// TODO 自动生成的方法存根
BigInteger a[]=new BigInteger[1005];
a[1]=a[2]=BigInteger.valueOf(1);
for (int i = 3; i <=1000; i++) {
a[i]=a[i-1].add(a[i-2]);
}
int n=cin.nextInt();
while (n-->0) {
int m=cin.nextInt();
System.out.println(a[m].toString());
}
}
}