#include <iostream> #include <set> #include <math.h> using namespace std; // Wygenerowany fibbonaci set<int> Fib; int limit = 1000000000; void ILO(int n) { if (n == 0) { cout << "TAK" << endl; return; } set<int>::iterator it = Fib.begin(); int i = *it; while (i <= ceil(sqrt(n))) { if (n%i == 0 && Fib.find(n / i) != Fib.end()) { cout << "TAK" << endl; return; } i = *++it; } cout << "NIE" << endl; } int main() { int a = 0; int b = 1; int c = a + b; while (b <= limit) { c = a + b; Fib.insert(c); a = b; b = c; } int n; cin >> n; while (cin >> n) { ILO(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 46 47 48 49 50 | #include <iostream> #include <set> #include <math.h> using namespace std; // Wygenerowany fibbonaci set<int> Fib; int limit = 1000000000; void ILO(int n) { if (n == 0) { cout << "TAK" << endl; return; } set<int>::iterator it = Fib.begin(); int i = *it; while (i <= ceil(sqrt(n))) { if (n%i == 0 && Fib.find(n / i) != Fib.end()) { cout << "TAK" << endl; return; } i = *++it; } cout << "NIE" << endl; } int main() { int a = 0; int b = 1; int c = a + b; while (b <= limit) { c = a + b; Fib.insert(c); a = b; b = c; } int n; cin >> n; while (cin >> n) { ILO(n); } return 0; } |