#include <set> #include <vector> #include <cstdio> using namespace std; int main(int argc, char* argv[]) { vector<long long> fib; fib.push_back(0LL); fib.push_back(1LL); while(fib.back() < 1e9) fib.push_back((*(fib.rbegin())) + (*(fib.rbegin()+1))); // for(long long f : fib) // fprintf(stderr, "\t%d", (int)f); // fprintf(stderr,"\n\n\n"); set<int> prodFib; for(long long fa : fib) for(long long fb : fib) { long long prod = fa * fb; if(prod <= 1e9) { prodFib.insert((int)prod); } } // for(long long p : prodFib) // fprintf(stderr, "\t%lld", p); // fprintf(stderr,"\n\n\n"); int N; scanf("%d", &N); for(int i=0; i<N; i++) { int curr; scanf("%d", &curr); if(prodFib.find(curr) == prodFib.end()) printf("NIE\n"); else printf("TAK\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 | #include <set> #include <vector> #include <cstdio> using namespace std; int main(int argc, char* argv[]) { vector<long long> fib; fib.push_back(0LL); fib.push_back(1LL); while(fib.back() < 1e9) fib.push_back((*(fib.rbegin())) + (*(fib.rbegin()+1))); // for(long long f : fib) // fprintf(stderr, "\t%d", (int)f); // fprintf(stderr,"\n\n\n"); set<int> prodFib; for(long long fa : fib) for(long long fb : fib) { long long prod = fa * fb; if(prod <= 1e9) { prodFib.insert((int)prod); } } // for(long long p : prodFib) // fprintf(stderr, "\t%lld", p); // fprintf(stderr,"\n\n\n"); int N; scanf("%d", &N); for(int i=0; i<N; i++) { int curr; scanf("%d", &curr); if(prodFib.find(curr) == prodFib.end()) printf("NIE\n"); else printf("TAK\n"); } return 0; } |