#include<cstdio> #include<vector> #include<algorithm> using namespace std; vector<int> F; inline bool isFibonacci(int n) { return binary_search( F.begin(), F.end(), n ); } void prepare() { F.push_back(0); F.push_back(1); for (int k=2; F[k-1]+F[k-2]<=1e9; k++) F.push_back(F[k-1]+F[k-2]); } bool solve(int n) { if ( isFibonacci(n) ) return true; for (unsigned int k=1; k<F.size(); k++) if ( n%F[k] == 0 && isFibonacci(n/F[k]) ) return true; return false; } int main() { prepare(); int T; scanf("%d", &T); while(T--) { int n; scanf("%d", &n); puts( solve(n) ? "TAK" : "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 | #include<cstdio> #include<vector> #include<algorithm> using namespace std; vector<int> F; inline bool isFibonacci(int n) { return binary_search( F.begin(), F.end(), n ); } void prepare() { F.push_back(0); F.push_back(1); for (int k=2; F[k-1]+F[k-2]<=1e9; k++) F.push_back(F[k-1]+F[k-2]); } bool solve(int n) { if ( isFibonacci(n) ) return true; for (unsigned int k=1; k<F.size(); k++) if ( n%F[k] == 0 && isFibonacci(n/F[k]) ) return true; return false; } int main() { prepare(); int T; scanf("%d", &T); while(T--) { int n; scanf("%d", &n); puts( solve(n) ? "TAK" : "NIE" ); } return 0; } |