#include <iostream> bool check_if_fib(double n); void update_fib(int & prev, int & curr); int main() { using namespace std; int k; cin >> k; int num[k]; for(int i=0; i<k; i++) { cin >> num[i]; } int prev, curr; int & ref_fib_p = prev; int & ref_fib_c = curr; for(int i=0; i<k; i++) { prev = 0; curr = 1; if(check_if_fib(num[i])) { if(i != k-1) { cout << "TAK" << endl; } else { cout << "TAK"; } } else { prev = 1; curr = 2; int j; for(j=2; j<=num[i]/2; ) { if(num[i]%j == 0) { double old_num = num[i]/j; if(check_if_fib(old_num) ) { if(i != k-1) { cout << "TAK" << endl; } else { cout << "TAK"; } break; } } update_fib(prev, curr); j = curr; } if(j > num[i]/2) { if(i != k-1) { cout << "NIE" << endl; } else { cout << "NIE"; } } } } return 0; } bool check_if_fib(double n) { int prev = 0, curr = 1; int & ref_fib_p = prev; int & ref_fib_c = curr; if(n == 0) { return true; } while(curr <= n) { if(prev == 0) { if(n == prev) { return true; } } if(n == curr) { return true; } else { update_fib(ref_fib_p, ref_fib_c); } } return false; } void update_fib(int & prev, int & curr) { using namespace std; int help; help = curr; curr += prev; prev = help; return; }
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | #include <iostream> bool check_if_fib(double n); void update_fib(int & prev, int & curr); int main() { using namespace std; int k; cin >> k; int num[k]; for(int i=0; i<k; i++) { cin >> num[i]; } int prev, curr; int & ref_fib_p = prev; int & ref_fib_c = curr; for(int i=0; i<k; i++) { prev = 0; curr = 1; if(check_if_fib(num[i])) { if(i != k-1) { cout << "TAK" << endl; } else { cout << "TAK"; } } else { prev = 1; curr = 2; int j; for(j=2; j<=num[i]/2; ) { if(num[i]%j == 0) { double old_num = num[i]/j; if(check_if_fib(old_num) ) { if(i != k-1) { cout << "TAK" << endl; } else { cout << "TAK"; } break; } } update_fib(prev, curr); j = curr; } if(j > num[i]/2) { if(i != k-1) { cout << "NIE" << endl; } else { cout << "NIE"; } } } } return 0; } bool check_if_fib(double n) { int prev = 0, curr = 1; int & ref_fib_p = prev; int & ref_fib_c = curr; if(n == 0) { return true; } while(curr <= n) { if(prev == 0) { if(n == prev) { return true; } } if(n == curr) { return true; } else { update_fib(ref_fib_p, ref_fib_c); } } return false; } void update_fib(int & prev, int & curr) { using namespace std; int help; help = curr; curr += prev; prev = help; return; } |