#include <iostream>
#include <cctype>
#include <set>
typedef unsigned int uint;
uint get_uint()
{
int c;
while (isspace(c = std::cin.get()));
uint value = (c - '0');
while (isdigit(c = std::cin.get()))
{
value = (10 * value) + (c - '0');
}
return value;
}
typedef std::set<uint> uint_set;
uint_set fib;
void init_fib(uint max_fib)
{
uint f[2] = { 0, 1 };
uint idx = 1;
while (f[idx] < max_fib)
{
idx = 1 - idx;
f[idx] = f[0] + f[1];
fib.insert(f[idx]);
}
}
bool ilo_test(uint x)
{
if (x == 0)
{
return true;
}
for (uint p : fib)
{
if (p * p > x)
{
break;
}
if (x % p == 0 && fib.count(x / p))
{
return true;
}
}
return false;
}
void ilo()
{
uint n = get_uint();
std::cout << (ilo_test(n) ? "TAK\n" : "NIE\n");
}
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
init_fib(1000000001);
uint t = get_uint();
for (uint i = 0; i < t; ++i)
{
ilo();
}
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | #include <iostream> #include <cctype> #include <set> typedef unsigned int uint; uint get_uint() { int c; while (isspace(c = std::cin.get())); uint value = (c - '0'); while (isdigit(c = std::cin.get())) { value = (10 * value) + (c - '0'); } return value; } typedef std::set<uint> uint_set; uint_set fib; void init_fib(uint max_fib) { uint f[2] = { 0, 1 }; uint idx = 1; while (f[idx] < max_fib) { idx = 1 - idx; f[idx] = f[0] + f[1]; fib.insert(f[idx]); } } bool ilo_test(uint x) { if (x == 0) { return true; } for (uint p : fib) { if (p * p > x) { break; } if (x % p == 0 && fib.count(x / p)) { return true; } } return false; } void ilo() { uint n = get_uint(); std::cout << (ilo_test(n) ? "TAK\n" : "NIE\n"); } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); init_fib(1000000001); uint t = get_uint(); for (uint i = 0; i < t; ++i) { ilo(); } return 0; } |
English