#include <iostream> using namespace std; typedef long long LL; const int MAXF = 100; const int MAXN = (1<<30); LL f[MAXF]; int maxf; bool mult(LL a) { for (int i = 0; i < maxf; ++i) { for (int j = 0; j < maxf; ++j) { if (f[i] * f[j] == a) return true; } } return false; } int main() { f[0] = 0; f[1] = 1; for (int i = 2; i < MAXF; ++i) { f[i] = f[i-1] + f[i-2]; if (f[i] > MAXN) { maxf = i; break; } } int n; cin >> n; for (int i = 0; i < n; ++i) { LL m; cin >> m; if (mult(m)) cout << "TAK\n"; else cout << "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 | #include <iostream> using namespace std; typedef long long LL; const int MAXF = 100; const int MAXN = (1<<30); LL f[MAXF]; int maxf; bool mult(LL a) { for (int i = 0; i < maxf; ++i) { for (int j = 0; j < maxf; ++j) { if (f[i] * f[j] == a) return true; } } return false; } int main() { f[0] = 0; f[1] = 1; for (int i = 2; i < MAXF; ++i) { f[i] = f[i-1] + f[i-2]; if (f[i] > MAXN) { maxf = i; break; } } int n; cin >> n; for (int i = 0; i < n; ++i) { LL m; cin >> m; if (mult(m)) cout << "TAK\n"; else cout << "NIE\n"; } return 0; } |