import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
System.out.println(fib(n));
}
public static int fib(int n) {
if (n <= 1) return n;
int a = 0, b = 1, res = 0;
for (int i = 2; i <= n; i++) {
res = (a + b) % 1000000007;
a = b;
b = res;
}
return res;
}
}
剑指offer10-1 斐波那契数列
最新推荐文章于 2024-08-29 18:44:48 发布