#include <cstdio> #include <cstring> #include <algorithm> using namespace std; int i,e; long long a,b=1,p=1,q,x; char s[22]; bool was; int main() { scanf("%s",s); e=strlen(s); if (e==1 && s[0]=='0') { puts("0"); return 0; } if (e==1 && s[0]=='1') { puts("1"); return 0; } for (i=1; i<e; i++) p*=10; q=p*10; sscanf(s,"%lld",&x); for (i=2; i<120000000; i++) { a+=b; swap(a,b); if (b>=p) was=true; if (b>=q) b-=q; if (x==b && was) { printf("%d\n",i); return 0; } } 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 | #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int i,e; long long a,b=1,p=1,q,x; char s[22]; bool was; int main() { scanf("%s",s); e=strlen(s); if (e==1 && s[0]=='0') { puts("0"); return 0; } if (e==1 && s[0]=='1') { puts("1"); return 0; } for (i=1; i<e; i++) p*=10; q=p*10; sscanf(s,"%lld",&x); for (i=2; i<120000000; i++) { a+=b; swap(a,b); if (b>=p) was=true; if (b>=q) b-=q; if (x==b && was) { printf("%d\n",i); return 0; } } puts("NIE"); return 0; } |