using namespace std; #include<cstdio> #include<iostream> int main() { const int MaxFib = 1000000000; int* fib = new int[44]; fib[0] = 0; fib[1] = 1; int curfib = 1; int curindex = 2; while (curfib < MaxFib) { fib[curindex] = curfib; curfib = fib[curindex] + fib[curindex - 1]; curindex++; } int n, x, iloczyn; cin >> n; for (int i = 0; i < n; i++) { cin >> x; int j = 0, k = 44; bool exists = false; while (j <= k){ iloczyn = fib[j] * fib[k]; if (iloczyn > x) k--; else if (iloczyn < x) j++; else { exists = true; break; } } if (exists) cout << "TAK" <<endl; else cout << "NIE" << endl; } }
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 | using namespace std; #include<cstdio> #include<iostream> int main() { const int MaxFib = 1000000000; int* fib = new int[44]; fib[0] = 0; fib[1] = 1; int curfib = 1; int curindex = 2; while (curfib < MaxFib) { fib[curindex] = curfib; curfib = fib[curindex] + fib[curindex - 1]; curindex++; } int n, x, iloczyn; cin >> n; for (int i = 0; i < n; i++) { cin >> x; int j = 0, k = 44; bool exists = false; while (j <= k){ iloczyn = fib[j] * fib[k]; if (iloczyn > x) k--; else if (iloczyn < x) j++; else { exists = true; break; } } if (exists) cout << "TAK" <<endl; else cout << "NIE" << endl; } } |