#include <cstdio> #include <vector> #include <set> using namespace std; int n, fibsiz; vector<int> fib3; set<int> fib2; long long fib(int i) { for (; fibsiz<=i; fibsiz++) { fib3.push_back(fib3[fibsiz-2]+fib3[fibsiz-1]); fib2.insert(fib3[fibsiz]); } return fib3[i]; } bool solve() { for (int i=1; fib(i)*fib(i)<=n; i++) { if (n%fib(i)==0) { if (fib2.find(n/fib(i))!=fib2.end()) return true; } } return false; /* if (x<11 && x!=7) return true; if (x<13) return false; */ } int main() { int t; scanf("%d", &t); fib3.push_back(0); fib3.push_back(1); fibsiz=2; fprintf(stderr, "%lld\n", fib(45)); while (t--) { scanf("%d", &n); if (solve()) puts("TAK"); else puts("NIE"); } 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 | #include <cstdio> #include <vector> #include <set> using namespace std; int n, fibsiz; vector<int> fib3; set<int> fib2; long long fib(int i) { for (; fibsiz<=i; fibsiz++) { fib3.push_back(fib3[fibsiz-2]+fib3[fibsiz-1]); fib2.insert(fib3[fibsiz]); } return fib3[i]; } bool solve() { for (int i=1; fib(i)*fib(i)<=n; i++) { if (n%fib(i)==0) { if (fib2.find(n/fib(i))!=fib2.end()) return true; } } return false; /* if (x<11 && x!=7) return true; if (x<13) return false; */ } int main() { int t; scanf("%d", &t); fib3.push_back(0); fib3.push_back(1); fibsiz=2; fprintf(stderr, "%lld\n", fib(45)); while (t--) { scanf("%d", &n); if (solve()) puts("TAK"); else puts("NIE"); } return 0; } |