#include <iostream> #include <string> #include <cmath> using namespace std; long long conv(string s) { long long t = 0; for(auto c : s) t *= 10, t += c-'0'; return t; } int lims[10] = {0, 60, 300, 1500}; int mn[10] = {0, 0, 7, 12, 17, 21, 26, 31, 36, 40}; inline void inc_mod(int &a, int b, int lim) { if((a += b) >= lim) a -= lim; } int main() { for(int i = 4; i <= 9; ++i) lims[i] = lims[i-1] * 10; string s; cin >> s; int l = s.size(); if(l <= 9) { int r = -1; int f1 = 0, f2 = 1, lim = pow(10, l), rest = conv(s); for(int i = 0; i < lims[l]; i++) { r++; if(i >= mn[l] && f1 == rest) { cout << r << endl; goto C; } swap(f1, f2); inc_mod(f1, f2, lim); } } cout << "NIE" << endl; C:; 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 | #include <iostream> #include <string> #include <cmath> using namespace std; long long conv(string s) { long long t = 0; for(auto c : s) t *= 10, t += c-'0'; return t; } int lims[10] = {0, 60, 300, 1500}; int mn[10] = {0, 0, 7, 12, 17, 21, 26, 31, 36, 40}; inline void inc_mod(int &a, int b, int lim) { if((a += b) >= lim) a -= lim; } int main() { for(int i = 4; i <= 9; ++i) lims[i] = lims[i-1] * 10; string s; cin >> s; int l = s.size(); if(l <= 9) { int r = -1; int f1 = 0, f2 = 1, lim = pow(10, l), rest = conv(s); for(int i = 0; i < lims[l]; i++) { r++; if(i >= mn[l] && f1 == rest) { cout << r << endl; goto C; } swap(f1, f2); inc_mod(f1, f2, lim); } } cout << "NIE" << endl; C:; return 0; } |