#include <iostream> #include <string> #include <math.h> using namespace std; void zero ( int t[], int n ) { for ( int i = 0; i < n; ++i ) { t[i] = 0; } } void make ( int t[], int n ) { t[0] = 0; t[1] = 1; for ( int i = 2; i < n; ++i ) { t[i] = t[i - 1] + t[i - 2]; } } bool isFib ( int t[], int x, int n ) { for ( int i = 0; i < n; ++i ) { if ( x == t[i] ) { return true; } } return false; } int isDivided ( int t[], int x ) { for ( int k = 3; t[k] <= floor( sqrt(x) ); ++k ) { if ( x % t[k] == 0 ) { return x/t[k]; } } return -1; } int main () { const int n = 45; int fib[n]; zero ( fib, n ); make ( fib, n ); int counter, in; int curr = 0; cin >> counter; int test[counter]; for ( int i = 0; i < counter; ++i ) { test[i] = 0; } for ( int i = 0; i < counter; ++i) { cin >> in; test[i] = in; } for ( int i = 0; i < counter; ++i ) { if ( isFib ( fib, test[i], n ) ) { cout << "TAK" << endl; } else { int rest = 0; if ( ((rest = isDivided ( fib, test[i] )) != -1)) { if (isFib(fib, rest, n)) cout << "TAK" << endl; else cout << "NIE" << endl; } else { cout << "NIE" << endl; } } } }
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | #include <iostream> #include <string> #include <math.h> using namespace std; void zero ( int t[], int n ) { for ( int i = 0; i < n; ++i ) { t[i] = 0; } } void make ( int t[], int n ) { t[0] = 0; t[1] = 1; for ( int i = 2; i < n; ++i ) { t[i] = t[i - 1] + t[i - 2]; } } bool isFib ( int t[], int x, int n ) { for ( int i = 0; i < n; ++i ) { if ( x == t[i] ) { return true; } } return false; } int isDivided ( int t[], int x ) { for ( int k = 3; t[k] <= floor( sqrt(x) ); ++k ) { if ( x % t[k] == 0 ) { return x/t[k]; } } return -1; } int main () { const int n = 45; int fib[n]; zero ( fib, n ); make ( fib, n ); int counter, in; int curr = 0; cin >> counter; int test[counter]; for ( int i = 0; i < counter; ++i ) { test[i] = 0; } for ( int i = 0; i < counter; ++i) { cin >> in; test[i] = in; } for ( int i = 0; i < counter; ++i ) { if ( isFib ( fib, test[i], n ) ) { cout << "TAK" << endl; } else { int rest = 0; if ( ((rest = isDivided ( fib, test[i] )) != -1)) { if (isFib(fib, rest, n)) cout << "TAK" << endl; else cout << "NIE" << endl; } else { cout << "NIE" << endl; } } } } |