AcWing 741. 斐波那契数列
原题链接
简单
作者:
haah
,
2020-12-06 10:17:46
,
所有人可见
,
阅读 374
算法
JAVA
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* @Author: ChangAo
* @Date: 2020/12/2 21:50
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int max = 1000;
long[] Fib = fib(new long[max]);
int num = Integer.parseInt(br.readLine());
for (int i = 0; i < num; i++) {
String s = br.readLine();
System.out.println("Fib(" + s + ") = "+Fib[Integer.parseInt(s)]);
}
}
public static long[] fib(long[] a){
long[] fib = new long[a.length];
fib[0] = 0;
fib[1] = 1;
for (int i = 2; i < a.length; i++) {
fib[i] = fib[i-1] + fib[i - 2];
}
return fib;
}
}