#include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <utility> #include <string> #include <map> #include <vector> #include <queue> #include <set> using namespace std; const int MAXN = 1000000000; const int MAXF = 45; int t, n; vector <int> fibs; void pre(); int main() { scanf("%d", &t); pre(); while(t--) { scanf("%d", &n); if(n == 0) { printf("TAK\n"); continue; } bool ok = false; for(int i = 0; i < MAXF; ++i) { if(n % fibs[i] == 0) { int tmp = n / fibs[i]; if(binary_search(fibs.begin(), fibs.end(), tmp)) { ok = true; break; } } } if(ok) printf("TAK\n"); else printf("NIE\n"); } return 0; } void pre() { fibs.resize(MAXF); fibs[0] = fibs[1] = 1; for(int i = 2; i < MAXF; ++i) { fibs[i] = fibs[i - 1] + fibs[i - 2]; } }
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 | #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <utility> #include <string> #include <map> #include <vector> #include <queue> #include <set> using namespace std; const int MAXN = 1000000000; const int MAXF = 45; int t, n; vector <int> fibs; void pre(); int main() { scanf("%d", &t); pre(); while(t--) { scanf("%d", &n); if(n == 0) { printf("TAK\n"); continue; } bool ok = false; for(int i = 0; i < MAXF; ++i) { if(n % fibs[i] == 0) { int tmp = n / fibs[i]; if(binary_search(fibs.begin(), fibs.end(), tmp)) { ok = true; break; } } } if(ok) printf("TAK\n"); else printf("NIE\n"); } return 0; } void pre() { fibs.resize(MAXF); fibs[0] = fibs[1] = 1; for(int i = 2; i < MAXF; ++i) { fibs[i] = fibs[i - 1] + fibs[i - 2]; } } |