#include <algorithm> #include <iostream> #include <vector> using namespace std; #define REP(i,n) for(int _n=n, i=0;i<_n;++i) typedef long long LL; const int MAX = 1000000000; vector<int> FIBS; vector<int> FIBPRODUCTS; void Precompute() { { LL a = 0, b=1; while(a<MAX) { FIBS.push_back(static_cast<int>(a)); LL c = a+b; a=b; b=c; } } for(int a:FIBS) for(int b:FIBS) { LL p = static_cast<LL>(a) * b; if(p>MAX) continue; FIBPRODUCTS.push_back(static_cast<int>(p)); } sort(FIBPRODUCTS.begin(), FIBPRODUCTS.end()); FIBPRODUCTS.erase(unique(FIBPRODUCTS.begin(), FIBPRODUCTS.end()), FIBPRODUCTS.end()); } bool Solve(int x) { auto it = lower_bound(FIBPRODUCTS.begin(), FIBPRODUCTS.end(), x); return it != FIBPRODUCTS.end() && *it == x; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); Precompute(); int ntc; cin >> ntc; REP(tc,ntc) { int x; cin >> x; bool res = Solve(x); cout << (res?"TAK\n":"NIE\n"); } }
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 | #include <algorithm> #include <iostream> #include <vector> using namespace std; #define REP(i,n) for(int _n=n, i=0;i<_n;++i) typedef long long LL; const int MAX = 1000000000; vector<int> FIBS; vector<int> FIBPRODUCTS; void Precompute() { { LL a = 0, b=1; while(a<MAX) { FIBS.push_back(static_cast<int>(a)); LL c = a+b; a=b; b=c; } } for(int a:FIBS) for(int b:FIBS) { LL p = static_cast<LL>(a) * b; if(p>MAX) continue; FIBPRODUCTS.push_back(static_cast<int>(p)); } sort(FIBPRODUCTS.begin(), FIBPRODUCTS.end()); FIBPRODUCTS.erase(unique(FIBPRODUCTS.begin(), FIBPRODUCTS.end()), FIBPRODUCTS.end()); } bool Solve(int x) { auto it = lower_bound(FIBPRODUCTS.begin(), FIBPRODUCTS.end(), x); return it != FIBPRODUCTS.end() && *it == x; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); Precompute(); int ntc; cin >> ntc; REP(tc,ntc) { int x; cin >> x; bool res = Solve(x); cout << (res?"TAK\n":"NIE\n"); } } |