#include <iostream> #include <algorithm> #include <vector> using namespace std; vector<int> FIBB; bool find(int n) { if (n==*lower_bound(FIBB.begin(), FIBB.end(), n)) { return true; } else { return false; } } void testcase() { int n; cin >> n; while (FIBB.back() < n) { int size = FIBB.size(); FIBB.push_back(FIBB[size-1] + FIBB[size-2]); } if (find(n)) { cout << "TAK" << endl; return; } for(int i = 1; i < FIBB.size(); i++) { if (n % FIBB[i] == 0 && find(n/FIBB[i])) { cout << "TAK" << endl; return; } } cout << "NIE" << endl; return; } int main () { FIBB.push_back(0); FIBB.push_back(1); int t; cin >> t; while (t--) { testcase(); } 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 | #include <iostream> #include <algorithm> #include <vector> using namespace std; vector<int> FIBB; bool find(int n) { if (n==*lower_bound(FIBB.begin(), FIBB.end(), n)) { return true; } else { return false; } } void testcase() { int n; cin >> n; while (FIBB.back() < n) { int size = FIBB.size(); FIBB.push_back(FIBB[size-1] + FIBB[size-2]); } if (find(n)) { cout << "TAK" << endl; return; } for(int i = 1; i < FIBB.size(); i++) { if (n % FIBB[i] == 0 && find(n/FIBB[i])) { cout << "TAK" << endl; return; } } cout << "NIE" << endl; return; } int main () { FIBB.push_back(0); FIBB.push_back(1); int t; cin >> t; while (t--) { testcase(); } return 0; } |