#include <bits/stdc++.h> using namespace std; char N[19]; int d, z, O[19] = {0,2,7,12,17,21,26,31,36,40,45,50,55,60,64,69,74,79,84}; long long a, b, c, n, p, C[19] = {0, 60, 300, 1500}; int main() { for (int i = 4; i < 19; ++i) { C[i] = 10 * C[i - 1]; } while (scanf("%s", N) == 1) { for (d = n = 0, p = 1; N[d]; ++d) { n = n * 10 + N[d] - '0'; p *= 10; } if (d == 1 && n < 2) { printf("%lld\n", n); continue; } a = 0; b = 1; z = 0; for (int i = 2; i <= C[d]; ++i) { c = (a + b) % p; if (i >= O[d] && c == n) { printf("%d\n", i); z = 1; break;; } a = b; b = c; } if (!z) { puts("NIE"); } } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <bits/stdc++.h> using namespace std; char N[19]; int d, z, O[19] = {0,2,7,12,17,21,26,31,36,40,45,50,55,60,64,69,74,79,84}; long long a, b, c, n, p, C[19] = {0, 60, 300, 1500}; int main() { for (int i = 4; i < 19; ++i) { C[i] = 10 * C[i - 1]; } while (scanf("%s", N) == 1) { for (d = n = 0, p = 1; N[d]; ++d) { n = n * 10 + N[d] - '0'; p *= 10; } if (d == 1 && n < 2) { printf("%lld\n", n); continue; } a = 0; b = 1; z = 0; for (int i = 2; i <= C[d]; ++i) { c = (a + b) % p; if (i >= O[d] && c == n) { printf("%d\n", i); z = 1; break;; } a = b; b = c; } if (!z) { puts("NIE"); } } return 0; } |