#include<iostream> #include<cstdio> #include<string> using namespace std; int id, ip, t[100], d[100], p[100]; int res, s[100], dl, lc; string slowo; bool blad, jest; int main() { cin>>slowo; dl = slowo.size(); for( int a = 0; a < dl; a++ )s[a+1] = int( slowo[a] ) - int('0'); p[1] = 1; d[1] = 1; // ip = 1; // id = 1; for( int i = 3; i <= 1000000; i++ ) { res = 0; for( int b = 1; b <= dl; b++ ) { t[b] = ( p[b] + d[b] + res )%10; res = (p[b] + d[b] + res )/10; if( t[b] != 0 )lc = max( lc, b ); } // ip = id; // if( res && id <= dl )t[ ++id ] = res; for( int b = 1; b <= dl; b++ )p[b] = d[b]; for( int b = 1; b <= dl; b++ )d[b] = t[b]; if( res )lc = 100000; if( lc >= dl ) { for( int a = 1; a <= dl; a++ ) { if( s[dl - a + 1] != d[a] ) { blad = 1; break; } } if( !blad ) { // for( int a = 1; a <= 20; a++ )cout<<d[20-a+1]; // cout<<endl; cout<<i; jest = 1; break; } blad = 0; } } // cout<<id<<endl; if( !jest )cout<<"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 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 | #include<iostream> #include<cstdio> #include<string> using namespace std; int id, ip, t[100], d[100], p[100]; int res, s[100], dl, lc; string slowo; bool blad, jest; int main() { cin>>slowo; dl = slowo.size(); for( int a = 0; a < dl; a++ )s[a+1] = int( slowo[a] ) - int('0'); p[1] = 1; d[1] = 1; // ip = 1; // id = 1; for( int i = 3; i <= 1000000; i++ ) { res = 0; for( int b = 1; b <= dl; b++ ) { t[b] = ( p[b] + d[b] + res )%10; res = (p[b] + d[b] + res )/10; if( t[b] != 0 )lc = max( lc, b ); } // ip = id; // if( res && id <= dl )t[ ++id ] = res; for( int b = 1; b <= dl; b++ )p[b] = d[b]; for( int b = 1; b <= dl; b++ )d[b] = t[b]; if( res )lc = 100000; if( lc >= dl ) { for( int a = 1; a <= dl; a++ ) { if( s[dl - a + 1] != d[a] ) { blad = 1; break; } } if( !blad ) { // for( int a = 1; a <= 20; a++ )cout<<d[20-a+1]; // cout<<endl; cout<<i; jest = 1; break; } blad = 0; } } // cout<<id<<endl; if( !jest )cout<<"NIE"; return 0; } |