#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
namespace {
bool check(unsigned n)
{
if (n <= 1) return true;
static vector<unsigned> fibs = {1, 1};
while (fibs.back() < n) {
fibs.push_back(fibs.back() + fibs[fibs.size()-2]);
}
for (auto f: fibs) {
if (n % f != 0) continue;
if (binary_search(fibs.begin(), fibs.end(), n/f)) return true;
}
return false;
}
}
int main()
{
iostream::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t > 0) {
--t;
int n;
cin >> n;
cout << (check(n) ? "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 42 43 44 | #include <algorithm> #include <iostream> #include <vector> using namespace std; namespace { bool check(unsigned n) { if (n <= 1) return true; static vector<unsigned> fibs = {1, 1}; while (fibs.back() < n) { fibs.push_back(fibs.back() + fibs[fibs.size()-2]); } for (auto f: fibs) { if (n % f != 0) continue; if (binary_search(fibs.begin(), fibs.end(), n/f)) return true; } return false; } } int main() { iostream::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t > 0) { --t; int n; cin >> n; cout << (check(n) ? "TAK" : "NIE") << '\n'; } return 0; } |
English