//============================================================================ // Name : potyczki.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <vector> using namespace std; typedef long long u64; u64 BLN = 1000000000; vector<u64> makeFibsLessThan(u64 n) { vector<u64> f; f.push_back(0); f.push_back(1); while(f.back() < n) { int k = f.size(); f.push_back(f[k-1]+f[k-2]); } return f; } bool isFibMult(u64 n) { vector<u64> fibs = makeFibsLessThan(BLN); int N = fibs.size(); for (int i = 0; i < N; ++i) { for (int j = 0; j <= i; ++j) { if (fibs[i] * fibs[j] == n) return true; } } return false; } int gi(){ int n; scanf("%d", &n); return n; } int main() { int T = gi(); for (int t = 0; t < T; ++t) { if(isFibMult(gi())) puts("TAK"); else puts("NIE"); } 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 | //============================================================================ // Name : potyczki.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <vector> using namespace std; typedef long long u64; u64 BLN = 1000000000; vector<u64> makeFibsLessThan(u64 n) { vector<u64> f; f.push_back(0); f.push_back(1); while(f.back() < n) { int k = f.size(); f.push_back(f[k-1]+f[k-2]); } return f; } bool isFibMult(u64 n) { vector<u64> fibs = makeFibsLessThan(BLN); int N = fibs.size(); for (int i = 0; i < N; ++i) { for (int j = 0; j <= i; ++j) { if (fibs[i] * fibs[j] == n) return true; } } return false; } int gi(){ int n; scanf("%d", &n); return n; } int main() { int T = gi(); for (int t = 0; t < T; ++t) { if(isFibMult(gi())) puts("TAK"); else puts("NIE"); } return 0; } |