#include <iostream> #include <vector> using namespace std; const int limit = 1000 * 1000 * 1000 + 1; vector<int> fibb_num; void prepare() { fibb_num.push_back(0); fibb_num.push_back(1); while (fibb_num[fibb_num.size() - 2] + fibb_num[fibb_num.size() - 1] < limit) { fibb_num.push_back( fibb_num[fibb_num.size() - 2] + fibb_num[fibb_num.size() - 1]); } } bool smart_check(int number) { int b = 0; int e = fibb_num.size() - 1; while (b <= e) { if ((long long) fibb_num[b] * (long long) fibb_num[e] == number) { return true; } if ((long long) fibb_num[b] * (long long) fibb_num[e] < number) { ++b; } else { --e; } } return false; } void one_case() { int number; cin >> number; cout << (smart_check(number) ? "TAK" : "NIE") << endl; } int main() { int tc; ios_base::sync_with_stdio(0); prepare(); cin >> tc; while (tc--) { one_case(); } 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 <vector> using namespace std; const int limit = 1000 * 1000 * 1000 + 1; vector<int> fibb_num; void prepare() { fibb_num.push_back(0); fibb_num.push_back(1); while (fibb_num[fibb_num.size() - 2] + fibb_num[fibb_num.size() - 1] < limit) { fibb_num.push_back( fibb_num[fibb_num.size() - 2] + fibb_num[fibb_num.size() - 1]); } } bool smart_check(int number) { int b = 0; int e = fibb_num.size() - 1; while (b <= e) { if ((long long) fibb_num[b] * (long long) fibb_num[e] == number) { return true; } if ((long long) fibb_num[b] * (long long) fibb_num[e] < number) { ++b; } else { --e; } } return false; } void one_case() { int number; cin >> number; cout << (smart_check(number) ? "TAK" : "NIE") << endl; } int main() { int tc; ios_base::sync_with_stdio(0); prepare(); cin >> tc; while (tc--) { one_case(); } return 0; } |