#include <cstdio> typedef unsigned int UI; const int MAX = 46; UI fib[MAX]; bool isInside(UI num) { int l = 0; int r = MAX-1; while(l<=r) { int c = (l+r)/2; if(fib[c] == num) return true; else if(fib[c] < num) l = c+1; else r = c-1; } return false; } bool check(UI num) { if(num == 0) return true; for(int i = 1; i<MAX; i++) { if(num%fib[i] == 0) if(isInside(num/fib[i])) return true; } return false; } int main() { UI a=1, b=0; fib[0] = 0; fib[1] = 1; for(int i = 2; i<MAX; i++) { fib[i] = fib[i-1] + fib[i-2]; } int N; std::scanf("%d", &N); for(int i = 0; i<N; i++) { UI num; std::scanf("%u", &num); std::printf(check(num) ? "TAK\n" : "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 | #include <cstdio> typedef unsigned int UI; const int MAX = 46; UI fib[MAX]; bool isInside(UI num) { int l = 0; int r = MAX-1; while(l<=r) { int c = (l+r)/2; if(fib[c] == num) return true; else if(fib[c] < num) l = c+1; else r = c-1; } return false; } bool check(UI num) { if(num == 0) return true; for(int i = 1; i<MAX; i++) { if(num%fib[i] == 0) if(isInside(num/fib[i])) return true; } return false; } int main() { UI a=1, b=0; fib[0] = 0; fib[1] = 1; for(int i = 2; i<MAX; i++) { fib[i] = fib[i-1] + fib[i-2]; } int N; std::scanf("%d", &N); for(int i = 0; i<N; i++) { UI num; std::scanf("%u", &num); std::printf(check(num) ? "TAK\n" : "NIE\n"); } return 0; } |