0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-24 18:08:47 +00:00
OI-codes/Luogu/problem/P4994/P4994.cpp

38 lines
669 B
C++
Raw Normal View History

2020-09-21 11:48:40 +00:00
// R38706118
#include <bits/stdc++.h>
using namespace std;
long long a[10000000];
long long dfib(long long x, long long m) {
if (a[x] != -1) {
return a[x];
}
if (x == 0) {
a[x] = 0 % m;
return 0;
}
if (x == 1) {
a[x] = 1 % m;
return 1;
}
a[x] = (dfib(x - 1, m) + dfib(x - 2, m)) % m;
return a[x];
}
int main() {
long long m;
memset(a, 0xff, sizeof(a));
cin >> m;
for (int i = 2; i < m * m; i++) {
// cout << i << ' ' << dfib(i, m) << endl;
if (dfib(i, m) == 0 && dfib(i + 1, m) == 1) {
cout << i;
break;
}
}
return 0;
}