#include <cstdio> #include <cstring> #include <cstdlib> using namespace std; const int MAX_N = 18; unsigned long long compute(unsigned long long cllu, int n) { unsigned long long pow = 1; for (int i = 0; i < n - 1; i++) pow *= 10; unsigned long long cycle_pow = pow; unsigned long long mod_pow = pow * 10; unsigned long long cycle; if (n == 1) cycle = 60; else if (n == 2) cycle = 300; else cycle = 15 * cycle_pow; unsigned long long fn1 = 0; if (cllu == fn1) return 10 * cycle; unsigned long long fn2 = 1; if (cllu == fn2) return 1 + 10 * cycle; for (unsigned long long i = 2; i < cycle; i++) { unsigned long long fn = (fn1 + fn2) % mod_pow; if (fn == cllu) { return i + 10 * cycle; } fn1 = fn2; fn2 = fn; } return -1; } int main() { char cstr[MAX_N + 1]; scanf("%s", cstr); int n = strlen(cstr); unsigned long long cllu = strtoull(cstr, NULL, 10); unsigned long long res = compute(cllu, n); if (res != -1) printf("%llu\n", res); else printf("NIE\n"); 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 40 41 42 43 44 45 46 47 | #include <cstdio> #include <cstring> #include <cstdlib> using namespace std; const int MAX_N = 18; unsigned long long compute(unsigned long long cllu, int n) { unsigned long long pow = 1; for (int i = 0; i < n - 1; i++) pow *= 10; unsigned long long cycle_pow = pow; unsigned long long mod_pow = pow * 10; unsigned long long cycle; if (n == 1) cycle = 60; else if (n == 2) cycle = 300; else cycle = 15 * cycle_pow; unsigned long long fn1 = 0; if (cllu == fn1) return 10 * cycle; unsigned long long fn2 = 1; if (cllu == fn2) return 1 + 10 * cycle; for (unsigned long long i = 2; i < cycle; i++) { unsigned long long fn = (fn1 + fn2) % mod_pow; if (fn == cllu) { return i + 10 * cycle; } fn1 = fn2; fn2 = fn; } return -1; } int main() { char cstr[MAX_N + 1]; scanf("%s", cstr); int n = strlen(cstr); unsigned long long cllu = strtoull(cstr, NULL, 10); unsigned long long res = compute(cllu, n); if (res != -1) printf("%llu\n", res); else printf("NIE\n"); return 0; } |