#include <cstdio> #include <queue> using namespace std; bool *fib = new bool[1000001]; int fib1 = 1; int fib2 = 2; bool is_fib(int k){ if(k <= 1000000) return fib[k]; int f1 = fib1; int f2 = fib2; while(f2 < k){ if(f2 == k) return true; int tmp = f1 + f2; f1 = f2; f2 = tmp; } return false; } int main() { fib[0] = true; fib[1] = true; while(fib2 <= 1000000){ fib[fib2] = true; int tmp = fib1 + fib2; fib1 = fib2; fib2 = tmp; } int t; scanf("%d", &t); int n; int k = 1; bool is_mul; while(t--){ is_mul = false; k = 1; scanf("%d", &n); while(k <= n / 2 + 1){ if(!fib[k]){ k++; continue; } if(n % k == 0 && is_fib(n / k)){ is_mul = true; break; } k++; } if(is_mul) printf("TAK\n"); else printf("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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | #include <cstdio> #include <queue> using namespace std; bool *fib = new bool[1000001]; int fib1 = 1; int fib2 = 2; bool is_fib(int k){ if(k <= 1000000) return fib[k]; int f1 = fib1; int f2 = fib2; while(f2 < k){ if(f2 == k) return true; int tmp = f1 + f2; f1 = f2; f2 = tmp; } return false; } int main() { fib[0] = true; fib[1] = true; while(fib2 <= 1000000){ fib[fib2] = true; int tmp = fib1 + fib2; fib1 = fib2; fib2 = tmp; } int t; scanf("%d", &t); int n; int k = 1; bool is_mul; while(t--){ is_mul = false; k = 1; scanf("%d", &n); while(k <= n / 2 + 1){ if(!fib[k]){ k++; continue; } if(n % k == 0 && is_fib(n / k)){ is_mul = true; break; } k++; } if(is_mul) printf("TAK\n"); else printf("NIE\n"); } return 0; } |