#include <iostream> #include <vector> typedef unsigned int uint; using namespace std; bool isProductOfFibMultiplication(uint n, vector<int>& fibNumbers) { uint fibSize = fibNumbers.size(); uint product = 0; for(uint i=0; i<fibSize; ++i) { for(uint j=0; j<fibSize; ++j) { product = fibNumbers[i] * fibNumbers[j]; if(n == product) { return true; } if(product > n) { break; } } } return false; } void computeFibNumbers(vector<int>& fibNumbers) { const uint MAX_NUMBER = 1000000000; fibNumbers.push_back(0); fibNumbers.push_back(1); uint secondLast = 0, last = 1, toAdd = 1; while(toAdd <= MAX_NUMBER) { fibNumbers.push_back(toAdd); secondLast = last; last = toAdd; toAdd = secondLast + last; } } int main(int argc, char* argv[]) { vector<int> fibNumbers; computeFibNumbers(fibNumbers); /* uint fibSize = fibNumbers.size(); for(uint i=0; i<fibSize; ++i) { cout << fibNumbers[i] << endl; } */ uint t = 0; cin >> t; uint* numbers = new uint[t]; for(uint i=0; i<t; ++i) { cin >> numbers[i]; } for(uint i=0; i<t; ++i) { //cout << numbers[i] << " "; if(isProductOfFibMultiplication(numbers[i], fibNumbers)) { cout << "TAK"; } else { cout << "NIE"; } cout << 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #include <iostream> #include <vector> typedef unsigned int uint; using namespace std; bool isProductOfFibMultiplication(uint n, vector<int>& fibNumbers) { uint fibSize = fibNumbers.size(); uint product = 0; for(uint i=0; i<fibSize; ++i) { for(uint j=0; j<fibSize; ++j) { product = fibNumbers[i] * fibNumbers[j]; if(n == product) { return true; } if(product > n) { break; } } } return false; } void computeFibNumbers(vector<int>& fibNumbers) { const uint MAX_NUMBER = 1000000000; fibNumbers.push_back(0); fibNumbers.push_back(1); uint secondLast = 0, last = 1, toAdd = 1; while(toAdd <= MAX_NUMBER) { fibNumbers.push_back(toAdd); secondLast = last; last = toAdd; toAdd = secondLast + last; } } int main(int argc, char* argv[]) { vector<int> fibNumbers; computeFibNumbers(fibNumbers); /* uint fibSize = fibNumbers.size(); for(uint i=0; i<fibSize; ++i) { cout << fibNumbers[i] << endl; } */ uint t = 0; cin >> t; uint* numbers = new uint[t]; for(uint i=0; i<t; ++i) { cin >> numbers[i]; } for(uint i=0; i<t; ++i) { //cout << numbers[i] << " "; if(isProductOfFibMultiplication(numbers[i], fibNumbers)) { cout << "TAK"; } else { cout << "NIE"; } cout << endl; } return 0; } |