// Iloczyn.cpp : Defines the entry point for the console application. // //#include "stdafx.h" #include <iostream> #include <vector> using namespace std; const int M = 51; int n; vector<long long> ff; void calculate() { long long a=0; long long b=1; ff.push_back(a); ff.push_back(b); for (long long i = 0; i < M; i++) { long long next = a+b; a = b; b = next; ff.push_back(next); } } void write() { for (long long i = 0; i < M; i++) { cout << i << " " << ff.at(i) << endl; } } bool isFib(long long d) { for (int i = 0; i < M; i++) { if (ff.at(i) == d) { return true; } } return false; } bool test(long long d) { if (d == 0 || d == 1) { return true; } for (int i = 3; i<=M; i++) { long long p = ff.at(i); if (p > d) { break; } if (d % p == 0) { long long q = d / p; if (isFib(q)) { return true; } } } return false; } int main() { calculate(); cin >> n; long long d; for (long long i = 1; i <=n ;i++) { cin >> d; if (test(d)) { cout << "TAK" << endl; } else { cout << "NIE" << endl; } } //write(); 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 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 | // Iloczyn.cpp : Defines the entry point for the console application. // //#include "stdafx.h" #include <iostream> #include <vector> using namespace std; const int M = 51; int n; vector<long long> ff; void calculate() { long long a=0; long long b=1; ff.push_back(a); ff.push_back(b); for (long long i = 0; i < M; i++) { long long next = a+b; a = b; b = next; ff.push_back(next); } } void write() { for (long long i = 0; i < M; i++) { cout << i << " " << ff.at(i) << endl; } } bool isFib(long long d) { for (int i = 0; i < M; i++) { if (ff.at(i) == d) { return true; } } return false; } bool test(long long d) { if (d == 0 || d == 1) { return true; } for (int i = 3; i<=M; i++) { long long p = ff.at(i); if (p > d) { break; } if (d % p == 0) { long long q = d / p; if (isFib(q)) { return true; } } } return false; } int main() { calculate(); cin >> n; long long d; for (long long i = 1; i <=n ;i++) { cin >> d; if (test(d)) { cout << "TAK" << endl; } else { cout << "NIE" << endl; } } //write(); return 0; } |