#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; const ll f_max = 10000000000L; vector<ll> fib; bool isFibMul(ll x) { if (!x) return true; for (int i = 1; i < fib.size(); i++) { if (x % fib[i] == 0) { if (find(fib.begin(), fib.end(), x / fib[i]) != fib.end()) return true; } } return false; } int main() { ios_base::sync_with_stdio(false); fib.push_back(0); fib.push_back(1); ll fi = fib[0] + fib[1]; while (fi < f_max) { fib.push_back(fi); fi = fib[fib.size()-2] + fib[fib.size()-1]; } int t; cin >> t; while (t--) { ll x; cin >> x; cout << (isFibMul(x) ? "TAK" : "NIE") << '\n'; } 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 | #include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; const ll f_max = 10000000000L; vector<ll> fib; bool isFibMul(ll x) { if (!x) return true; for (int i = 1; i < fib.size(); i++) { if (x % fib[i] == 0) { if (find(fib.begin(), fib.end(), x / fib[i]) != fib.end()) return true; } } return false; } int main() { ios_base::sync_with_stdio(false); fib.push_back(0); fib.push_back(1); ll fi = fib[0] + fib[1]; while (fi < f_max) { fib.push_back(fi); fi = fib[fib.size()-2] + fib[fib.size()-1]; } int t; cin >> t; while (t--) { ll x; cin >> x; cout << (isFibMul(x) ? "TAK" : "NIE") << '\n'; } return 0; } |