#include <cstdio> #include <vector> #define MAX_FIB 46 #define MAX 20000000 using namespace std; vector<long long> F; bool T[MAX]; int t,a; bool ok; long long bin(long long a) { int start=0, end=F.size()-1, mid; while(start<=end) { mid=(start+end)/2; if(F[mid]<a) start=mid+1; else if(F[mid]>a) end=mid-1; else return F[mid]; } return 0; } int main() { F.push_back(0); T[0]=true; F.push_back(1); T[1]=true; for(int i = 2; i < MAX_FIB; ++i) { F.push_back(F[F.size()-1]+F[F.size()-2]); if(i <= 36) T[F[i]]=true; } scanf("%d", &t); while(t--) { ok=false; scanf("%d", &a); for(int i = 1; i*i <= a; ++i) { if(a%i==0 && T[i] && bin(a/i)!=0) ok=true; if(ok) break; } if(ok) 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 | #include <cstdio> #include <vector> #define MAX_FIB 46 #define MAX 20000000 using namespace std; vector<long long> F; bool T[MAX]; int t,a; bool ok; long long bin(long long a) { int start=0, end=F.size()-1, mid; while(start<=end) { mid=(start+end)/2; if(F[mid]<a) start=mid+1; else if(F[mid]>a) end=mid-1; else return F[mid]; } return 0; } int main() { F.push_back(0); T[0]=true; F.push_back(1); T[1]=true; for(int i = 2; i < MAX_FIB; ++i) { F.push_back(F[F.size()-1]+F[F.size()-2]); if(i <= 36) T[F[i]]=true; } scanf("%d", &t); while(t--) { ok=false; scanf("%d", &a); for(int i = 1; i*i <= a; ++i) { if(a%i==0 && T[i] && bin(a/i)!=0) ok=true; if(ok) break; } if(ok) printf("TAK\n"); else printf("NIE\n"); } return 0; } |