You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
//递归,TLE
|
|
|
|
|
int fib(int n) {
|
|
|
|
|
if (n == 1) return 1;
|
|
|
|
|
if (n == 2) return 1;
|
|
|
|
|
return fib(n - 1) % 9997 + fib(n - 2) % 9997;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//while循环
|
|
|
|
|
int fib2(int n) {
|
|
|
|
|
if (n == 1) return 1;
|
|
|
|
|
if (n == 2) return 1;
|
|
|
|
|
int i = 3;
|
|
|
|
|
int a = 1, b = 1;
|
|
|
|
|
while (i <= n) {
|
|
|
|
|
int c = a % 9997 + b % 9997;
|
|
|
|
|
a = b % 9997;
|
|
|
|
|
b = c % 9997;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
int n;
|
|
|
|
|
cin >> n;
|
|
|
|
|
cout << fib2(n) << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|