#include <iostream> #include <algorithm> #include <vector> using namespace std; typedef long long ll; const int FIB_COUNT = 45; const ll MAX_FIB = 1000000000LL; ll fib[FIB_COUNT]; vector <ll> v; void gen_fib() { fib[0] = 0; fib[1] = 1; for (int i = 2; i < FIB_COUNT; ++i) fib[i] = fib[i-1] + fib[i-2]; } void gen_vec() { v.push_back(0); for (int i = 2; i < FIB_COUNT; ++i) for (int j = i; j < FIB_COUNT; ++j) { ll val = fib[i] * fib[j]; if (val <= MAX_FIB) v.push_back(val); else break; } sort(v.begin(), v.end()); } int main() { int t; ll n; gen_fib(); gen_vec(); cin >> t; for (int i = 0; i < t; ++i) { cin >> n; if (binary_search(v.begin(), v.end(), n)) cout << "TAK\n"; else cout <<"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 | #include <iostream> #include <algorithm> #include <vector> using namespace std; typedef long long ll; const int FIB_COUNT = 45; const ll MAX_FIB = 1000000000LL; ll fib[FIB_COUNT]; vector <ll> v; void gen_fib() { fib[0] = 0; fib[1] = 1; for (int i = 2; i < FIB_COUNT; ++i) fib[i] = fib[i-1] + fib[i-2]; } void gen_vec() { v.push_back(0); for (int i = 2; i < FIB_COUNT; ++i) for (int j = i; j < FIB_COUNT; ++j) { ll val = fib[i] * fib[j]; if (val <= MAX_FIB) v.push_back(val); else break; } sort(v.begin(), v.end()); } int main() { int t; ll n; gen_fib(); gen_vec(); cin >> t; for (int i = 0; i < t; ++i) { cin >> n; if (binary_search(v.begin(), v.end(), n)) cout << "TAK\n"; else cout <<"NIE\n"; } return 0; } |