#include <iostream> #include <map> #include <vector> using namespace std; map<long long, bool> mapa; vector<long long> tab; void fib(unsigned long long a, unsigned long long b, int i){ if(a+b > 1000000000) return; //cout << i << ":\t" << a+b << endl; mapa[a+b] = true; tab.push_back(a+b); fib(b, a+b, i+1); } bool podzielny(double a, double b){ if(a/b == (int)a/(int)b)return true; else return false; } int main() { //cout << "1:\t0\n"; //cout << "2:\t1\n"; fib(0, 1, 3); long long a; bool f; int n; cin >> n; while(n--){ f = false; cin >> a; for(int i = 0; tab[i] * tab[i] <= a; i++){ if(mapa[a/tab[i]] == true && podzielny(a, tab[i])){ cout << "TAK\n"; //cout << a << " " << tab[i] << endl; f = true; break; } } if(!f) 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 46 47 | #include <iostream> #include <map> #include <vector> using namespace std; map<long long, bool> mapa; vector<long long> tab; void fib(unsigned long long a, unsigned long long b, int i){ if(a+b > 1000000000) return; //cout << i << ":\t" << a+b << endl; mapa[a+b] = true; tab.push_back(a+b); fib(b, a+b, i+1); } bool podzielny(double a, double b){ if(a/b == (int)a/(int)b)return true; else return false; } int main() { //cout << "1:\t0\n"; //cout << "2:\t1\n"; fib(0, 1, 3); long long a; bool f; int n; cin >> n; while(n--){ f = false; cin >> a; for(int i = 0; tab[i] * tab[i] <= a; i++){ if(mapa[a/tab[i]] == true && podzielny(a, tab[i])){ cout << "TAK\n"; //cout << a << " " << tab[i] << endl; f = true; break; } } if(!f) cout << "NIE\n"; } return 0; } |