#include<stdio.h> #include<stdlib.h> #include<string> #include<stdint.h> #include<string.h> #ifndef DEBUG #define NDEBUG #endif // DEBUG #include<assert.h> #ifdef DEBUG #define log(format, ...) printf(format "\n", __VA_ARGS__) #else #define log(...) #endif using namespace std; int check(const char *val) { uint64_t fiba=0; uint64_t fibb=1; int valLen=strlen(val); char buf[24]; bool passed=false; uint64_t mod=1ULL; uint64_t c=0; for(int i=0;i<valLen;++i) { mod*=10ULL; c=c*10+(val[i]-'0'); } uint64_t min=mod/10; //printf("Val=%s, C=%llu, min=%llu, Mod=%llu\n",val, c,min,mod); int limit=1100000*(valLen<<2); for(int i=2;i<limit;++i) { uint64_t fibc=(fiba+fibb); if(passed || fibc>=min) { fibc%=mod; if(fibc==c) return i; passed=true; } fiba=fibb; fibb=fibc; } return -1; } int main(int argc, char** argv) { char in[20]; scanf("%s",in); int res=check(in); if(res==-1) printf("NIE\n"); else printf("%d\n",res); 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include<stdio.h> #include<stdlib.h> #include<string> #include<stdint.h> #include<string.h> #ifndef DEBUG #define NDEBUG #endif // DEBUG #include<assert.h> #ifdef DEBUG #define log(format, ...) printf(format "\n", __VA_ARGS__) #else #define log(...) #endif using namespace std; int check(const char *val) { uint64_t fiba=0; uint64_t fibb=1; int valLen=strlen(val); char buf[24]; bool passed=false; uint64_t mod=1ULL; uint64_t c=0; for(int i=0;i<valLen;++i) { mod*=10ULL; c=c*10+(val[i]-'0'); } uint64_t min=mod/10; //printf("Val=%s, C=%llu, min=%llu, Mod=%llu\n",val, c,min,mod); int limit=1100000*(valLen<<2); for(int i=2;i<limit;++i) { uint64_t fibc=(fiba+fibb); if(passed || fibc>=min) { fibc%=mod; if(fibc==c) return i; passed=true; } fiba=fibb; fibb=fibc; } return -1; } int main(int argc, char** argv) { char in[20]; scanf("%s",in); int res=check(in); if(res==-1) printf("NIE\n"); else printf("%d\n",res); return 0; } |