#include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; void displayValue(int number) { cout << number << ' '; } void CalculateFibonacciNumbers(int inputNumber, vector<int>& arrNumbers); bool IsValidNumber(int number, vector<int>& arrNumbers); int main() { vector<int> arrNumbers; int size; cin >> size; int *inputNumbers = new int[size]; int index = 0; while (index < size) { cin >> inputNumbers[index]; index++; } int max = *max_element(inputNumbers, inputNumbers + size); CalculateFibonacciNumbers(max, arrNumbers); for(index = 0; index < size; ++index) { string text = IsValidNumber(inputNumbers[index], arrNumbers) ? "TAK" : "NIE"; cout << text << endl; } delete [] inputNumbers; return 0; } void CalculateFibonacciNumbers(int inputNumber, vector<int>& arrNumbers) { int currentNumber = 0; int beforePreviousNumber = 0; int previousNumber = 1; arrNumbers.push_back(0); arrNumbers.push_back(1); while (currentNumber < inputNumber) { currentNumber = previousNumber + beforePreviousNumber; arrNumbers.push_back(currentNumber); beforePreviousNumber = previousNumber; previousNumber = currentNumber; } } bool IsValidNumber(int number, vector<int>& arrNumbers) { int count = arrNumbers.size(); for (int index1 = 1; index1 < count; ++index1) { int firstNumber = arrNumbers[index1]; for (int index2 = index1; index2 < count; ++index2) { int currentNumber = firstNumber * arrNumbers[index2]; if (currentNumber == number) { return true; } if (currentNumber > number) { break; } } } return false; }
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 87 88 89 90 91 92 93 | #include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; void displayValue(int number) { cout << number << ' '; } void CalculateFibonacciNumbers(int inputNumber, vector<int>& arrNumbers); bool IsValidNumber(int number, vector<int>& arrNumbers); int main() { vector<int> arrNumbers; int size; cin >> size; int *inputNumbers = new int[size]; int index = 0; while (index < size) { cin >> inputNumbers[index]; index++; } int max = *max_element(inputNumbers, inputNumbers + size); CalculateFibonacciNumbers(max, arrNumbers); for(index = 0; index < size; ++index) { string text = IsValidNumber(inputNumbers[index], arrNumbers) ? "TAK" : "NIE"; cout << text << endl; } delete [] inputNumbers; return 0; } void CalculateFibonacciNumbers(int inputNumber, vector<int>& arrNumbers) { int currentNumber = 0; int beforePreviousNumber = 0; int previousNumber = 1; arrNumbers.push_back(0); arrNumbers.push_back(1); while (currentNumber < inputNumber) { currentNumber = previousNumber + beforePreviousNumber; arrNumbers.push_back(currentNumber); beforePreviousNumber = previousNumber; previousNumber = currentNumber; } } bool IsValidNumber(int number, vector<int>& arrNumbers) { int count = arrNumbers.size(); for (int index1 = 1; index1 < count; ++index1) { int firstNumber = arrNumbers[index1]; for (int index2 = index1; index2 < count; ++index2) { int currentNumber = firstNumber * arrNumbers[index2]; if (currentNumber == number) { return true; } if (currentNumber > number) { break; } } } return false; } |