#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
int main()
{
const LL MAX_NUMBER = 1000000000;
ios_base::sync_with_stdio(0);
int t;
cin >> t;
vector<string> data;
set<LL> fibonacci;
// Generate fibonacci numbers
LL previous = 0;
LL current = 1;
while (current <= MAX_NUMBER)
{
LL p = previous;
previous = current;
current = current + p;
fibonacci.insert(current);
}
for (int i = 0; i < t; ++i)
{
int n;
cin >> n;
string result = "NIE";
for (set<LL>::iterator it = fibonacci.begin(); it != fibonacci.end(); ++it)
{
if (n % *it == 0)
{
if (fibonacci.count(n / *it) > 0)
{
result = "TAK";
break;
}
}
}
cout << result << endl;
}
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 | #include <iostream> #include <vector> #include <string> #include <set> using namespace std; typedef long long LL; int main() { const LL MAX_NUMBER = 1000000000; ios_base::sync_with_stdio(0); int t; cin >> t; vector<string> data; set<LL> fibonacci; // Generate fibonacci numbers LL previous = 0; LL current = 1; while (current <= MAX_NUMBER) { LL p = previous; previous = current; current = current + p; fibonacci.insert(current); } for (int i = 0; i < t; ++i) { int n; cin >> n; string result = "NIE"; for (set<LL>::iterator it = fibonacci.begin(); it != fibonacci.end(); ++it) { if (n % *it == 0) { if (fibonacci.count(n / *it) > 0) { result = "TAK"; break; } } } cout << result << endl; } return 0; } |
English