#include <cstdio> #include <set> using namespace std; typedef long long LL; const LL MAX = 1000000010; // 1000 * 1000 * 1000 int f[50]; set<int> s; void genFib() { f[0] = 0; f[1] = 1; for (int i = 2; i <= 45; ++i) f[i] = f[i-1] + f[i-2]; } void genProd() { for (int i = 0; i <= 45; ++i) for (int j = 0; j <= i; ++j) if ((LL)f[i] * f[j] <= MAX) s.insert(f[i] * f[j]); } int main () { int n, x; genFib(); genProd(); scanf ("%d", &n); for (int i = 0; i < n; ++i) { scanf ("%d", &x); if (s.find(x) != s.end()) 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 40 41 | #include <cstdio> #include <set> using namespace std; typedef long long LL; const LL MAX = 1000000010; // 1000 * 1000 * 1000 int f[50]; set<int> s; void genFib() { f[0] = 0; f[1] = 1; for (int i = 2; i <= 45; ++i) f[i] = f[i-1] + f[i-2]; } void genProd() { for (int i = 0; i <= 45; ++i) for (int j = 0; j <= i; ++j) if ((LL)f[i] * f[j] <= MAX) s.insert(f[i] * f[j]); } int main () { int n, x; genFib(); genProd(); scanf ("%d", &n); for (int i = 0; i < n; ++i) { scanf ("%d", &x); if (s.find(x) != s.end()) printf ("TAK\n"); else printf ("NIE\n"); } } |