#include<stdlib.h> #include<stdio.h> #include<algorithm> #include<iostream> #include<set> #include<string.h> #ifdef DEBUG #include<unistd.h> #endif typedef long long LL; typedef unsigned long long ULL; using namespace std; char in[20]; bool check (ULL f) { int i = strlen(in)-1; // printf("check %s and %llu\n",in,f); // sleep(1); while (i>=0) { // printf("compare %c and %llu\n",in[i],f%10ULL); if(f%10ULL+'0' != in[i] || (f==0)) return false; i--; f/=10ULL; } return true; } int main() { scanf("%s",in); ULL f_2=0; ULL f_1=1; if (check(f_1)) { printf("1\n"); } if (check(f_2)) { printf("0\n"); } ULL k = 2; while (k<10000000ULL) { ULL f=(f_1+f_2)%1000000000000000000ULL; if (check(f+1000000000000000000ULL)) { printf("%llu\n",k); return 0; } k++; f_2=f_1; f_1=f; } 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 48 49 50 51 52 53 54 55 56 57 | #include<stdlib.h> #include<stdio.h> #include<algorithm> #include<iostream> #include<set> #include<string.h> #ifdef DEBUG #include<unistd.h> #endif typedef long long LL; typedef unsigned long long ULL; using namespace std; char in[20]; bool check (ULL f) { int i = strlen(in)-1; // printf("check %s and %llu\n",in,f); // sleep(1); while (i>=0) { // printf("compare %c and %llu\n",in[i],f%10ULL); if(f%10ULL+'0' != in[i] || (f==0)) return false; i--; f/=10ULL; } return true; } int main() { scanf("%s",in); ULL f_2=0; ULL f_1=1; if (check(f_1)) { printf("1\n"); } if (check(f_2)) { printf("0\n"); } ULL k = 2; while (k<10000000ULL) { ULL f=(f_1+f_2)%1000000000000000000ULL; if (check(f+1000000000000000000ULL)) { printf("%llu\n",k); return 0; } k++; f_2=f_1; f_1=f; } printf("NIE\n"); return 0; } |