文章
20
粉丝
412
获赞
12
访问
163.2k
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
static BigInteger fibo[] = new BigInteger[1000005];
public static BigInteger Fibonacci(int n) {
if(fibo[n] != null) return fibo[n];
BigInteger b1 = BigInteger.ONE;
BigInteger b2 = b1;
BigInteger temp;
BigInteger r = new BigInteger(String.valueOf(1000000007));
if(n < 2) return b1;
for(int i = 1;i < n;i++) {
temp = b1.add(b2).remainder(r);
b1 = b2;
b2 = temp;
}
fibo[n] = b2;
return b2;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while(input.hasNext()) {
int n = input.nextInt();
BigInteger b = Fibonacci(n);
System.out.println(b);
}
input.close();
}
}
登录后发布评论
暂无评论,来抢沙发