#include <cstdio> #include <cstdlib> using namespace std; const int FIB_MAX = 45; int fib[FIB_MAX]; bool check(long long int n) { for (int i = 0; i < FIB_MAX; ++i) for (int j = 0; j < FIB_MAX; ++j) { long long int r = (long long int) fib[i] * (long long int) fib[j]; if (r == n) return true; } return false; } void init() { fib[0] = 0; fib[1] = 1; for (int i = 2; i < FIB_MAX; ++i) fib[i] = fib[i-1] + fib[i-2]; } int main() { int t; init(); scanf("%d\n", &t); for (int i = 0; i < t; ++i) { long long int n; scanf("%lld\n", &n); if (check(n)) printf("TAK\n"); else printf("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 | #include <cstdio> #include <cstdlib> using namespace std; const int FIB_MAX = 45; int fib[FIB_MAX]; bool check(long long int n) { for (int i = 0; i < FIB_MAX; ++i) for (int j = 0; j < FIB_MAX; ++j) { long long int r = (long long int) fib[i] * (long long int) fib[j]; if (r == n) return true; } return false; } void init() { fib[0] = 0; fib[1] = 1; for (int i = 2; i < FIB_MAX; ++i) fib[i] = fib[i-1] + fib[i-2]; } int main() { int t; init(); scanf("%d\n", &t); for (int i = 0; i < t; ++i) { long long int n; scanf("%lld\n", &n); if (check(n)) printf("TAK\n"); else printf("NIE\n"); } } |