“蓝桥杯”练习系统 - 入门训练 - Fibonacci数列
作者:互联网
思路:
直接打表, fib[n]即为所求. 注意取模运算的规则: (a + b) % c = (a % b + b % c) % c
1 #include <iostream> 2 using namespace std; 3 4 int fib[1000005]; 5 6 int main() 7 { 8 ios::sync_with_stdio(false); 9 cin.tie(0); 10 11 int n; 12 cin >> n; 13 fib[1] = fib[2] = 1; 14 for (int i = 3; i < 1000000; i++) 15 fib[i] = (fib[i - 1] % 10007 + fib[i - 2] % 10007) % 10007; 16 cout << fib[n] << endl; 17 18 return 0; 19 }
标签:fib,10007,false,数列,int,cin,蓝桥,Fibonacci 来源: https://www.cnblogs.com/AntonLiu/p/12246654.html