#include <iostream> #include <vector> int Fib[10001]; void initFib( int maxn ) { Fib[0] = 0; Fib[1] = 1; int ind = 2; while( Fib[ind-1] < maxn ) { Fib[ind] = Fib[ind-2]+Fib[ind-1]; ++ind; } } bool isIloczyn( int n ) { int indp = 2; int indk = 2; while( Fib[ indk ] < n ) ++indk; while( indp != indk ) { int iloczyn = Fib[indp]*Fib[indk]; if( iloczyn == n ) return true; else { if( iloczyn < n ) ++indp; else --indk; } } if( Fib[indp]*Fib[indk] == n ) return true; return false; } int main() { int t, an, maxn = 0; std::vector< int > n; std::cin >> t; for( int i=0; i<t; ++i ) { std::cin >> an; n.push_back( an ); if( maxn < an ) maxn = an; } initFib( maxn ); std::vector< int >::iterator it; for( it = n.begin(); it != n.end(); ++it ) { if( isIloczyn( *it ) ) std::cout << "TAK" << std::endl; else std::cout << "NIE" << std::endl; } 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 62 63 64 65 66 | #include <iostream> #include <vector> int Fib[10001]; void initFib( int maxn ) { Fib[0] = 0; Fib[1] = 1; int ind = 2; while( Fib[ind-1] < maxn ) { Fib[ind] = Fib[ind-2]+Fib[ind-1]; ++ind; } } bool isIloczyn( int n ) { int indp = 2; int indk = 2; while( Fib[ indk ] < n ) ++indk; while( indp != indk ) { int iloczyn = Fib[indp]*Fib[indk]; if( iloczyn == n ) return true; else { if( iloczyn < n ) ++indp; else --indk; } } if( Fib[indp]*Fib[indk] == n ) return true; return false; } int main() { int t, an, maxn = 0; std::vector< int > n; std::cin >> t; for( int i=0; i<t; ++i ) { std::cin >> an; n.push_back( an ); if( maxn < an ) maxn = an; } initFib( maxn ); std::vector< int >::iterator it; for( it = n.begin(); it != n.end(); ++it ) { if( isIloczyn( *it ) ) std::cout << "TAK" << std::endl; else std::cout << "NIE" << std::endl; } return 0; } |