#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
vector <int> fib;
bool czy(int n) { if(n==0) return 1;
int s = (int)sqrt(n);
int d = 0;
while (fib[d] <= s) d++;
d--;
for (; d > 0; d--) {
if ((n % fib[d]) == 0) {
if (binary_search(fib.begin(), fib.end(), int((int)n/(int)fib[d]))) {
return true;
}
}
}
return false;
}
int main() {
const int max = sqrt(1000000001);
fib.push_back(0);
fib.push_back(1);
while (1) {
int nowy = fib[fib.size()-1]+fib[fib.size()-2];
fib.push_back(nowy);
if (nowy > max) break;
}
int t; cin >> t;
bool wyn[t];
for (int i = 0; i < t; i++) {
int n;
cin >> n;
wyn[i] = czy(n);
}
for (int i = 0; i < t; i++) {
if (wyn[i]) cout << "TAK\n";
else cout << "NIE\n";
}
}
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 | #include <iostream> #include <cmath> #include <vector> #include <algorithm> using namespace std; vector <int> fib; bool czy(int n) { if(n==0) return 1; int s = (int)sqrt(n); int d = 0; while (fib[d] <= s) d++; d--; for (; d > 0; d--) { if ((n % fib[d]) == 0) { if (binary_search(fib.begin(), fib.end(), int((int)n/(int)fib[d]))) { return true; } } } return false; } int main() { const int max = sqrt(1000000001); fib.push_back(0); fib.push_back(1); while (1) { int nowy = fib[fib.size()-1]+fib[fib.size()-2]; fib.push_back(nowy); if (nowy > max) break; } int t; cin >> t; bool wyn[t]; for (int i = 0; i < t; i++) { int n; cin >> n; wyn[i] = czy(n); } for (int i = 0; i < t; i++) { if (wyn[i]) cout << "TAK\n"; else cout << "NIE\n"; } } |
English