#include <iostream> #include <set> #include <vector> using namespace std; const long long MAX_N = 1e9; vector<long long> fib; set<long long> is_fib; void preprocess() { fib.push_back(1); fib.push_back(1); for (int i = fib.size(); fib[i - 1] < MAX_N; ++i) { fib.push_back(fib[i - 1] + fib[i - 2]); } is_fib = set<long long>(fib.begin(), fib.end()); } bool is_fibonacci_product(long long n) { if (n == 0) { return true; } for (int i = 0; i < fib.size() && fib[i] <= n; ++i) { if (n % fib[i] == 0) { long long d = n / fib[i]; if (is_fib.count(d)) { return true; } } } return false; } void one() { long long n; cin >> n; cout << (is_fibonacci_product(n) ? "TAK" : "NIE") << "\n"; } int main() { preprocess(); int tests; cin >> tests; while (tests--) { one(); } }
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 | #include <iostream> #include <set> #include <vector> using namespace std; const long long MAX_N = 1e9; vector<long long> fib; set<long long> is_fib; void preprocess() { fib.push_back(1); fib.push_back(1); for (int i = fib.size(); fib[i - 1] < MAX_N; ++i) { fib.push_back(fib[i - 1] + fib[i - 2]); } is_fib = set<long long>(fib.begin(), fib.end()); } bool is_fibonacci_product(long long n) { if (n == 0) { return true; } for (int i = 0; i < fib.size() && fib[i] <= n; ++i) { if (n % fib[i] == 0) { long long d = n / fib[i]; if (is_fib.count(d)) { return true; } } } return false; } void one() { long long n; cin >> n; cout << (is_fibonacci_product(n) ? "TAK" : "NIE") << "\n"; } int main() { preprocess(); int tests; cin >> tests; while (tests--) { one(); } } |