//Jakub Bujak #include <cstdio> #include <vector> #define PB push_back using namespace std; bool found; int n, a; int fib[100]; vector<int> primes; bool isFibonacci(int x) { int count=0; while(x>=fib[count]) { if(x==fib[count]) return true; count++; } return false; } void factorization(int x) { primes.clear(); for(int i=1; i*i<=x; i++) { if(x%i==0) primes.PB(i); } } int main() { fib[1]=1; int curr=2; while(fib[curr-1]<1000000000) { fib[curr]=fib[curr-1]+fib[curr-2]; curr++; } scanf("%d", &n); for(int i=0; i<n; i++) { scanf("%d", &a); factorization(a); for(int p: primes) { if( isFibonacci(p) && isFibonacci(a/p) ) { printf("TAK\n"); found=true; continue; } } if(found) found=false; 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 | //Jakub Bujak #include <cstdio> #include <vector> #define PB push_back using namespace std; bool found; int n, a; int fib[100]; vector<int> primes; bool isFibonacci(int x) { int count=0; while(x>=fib[count]) { if(x==fib[count]) return true; count++; } return false; } void factorization(int x) { primes.clear(); for(int i=1; i*i<=x; i++) { if(x%i==0) primes.PB(i); } } int main() { fib[1]=1; int curr=2; while(fib[curr-1]<1000000000) { fib[curr]=fib[curr-1]+fib[curr-2]; curr++; } scanf("%d", &n); for(int i=0; i<n; i++) { scanf("%d", &a); factorization(a); for(int p: primes) { if( isFibonacci(p) && isFibonacci(a/p) ) { printf("TAK\n"); found=true; continue; } } if(found) found=false; else printf("NIE\n"); } return 0; } |