#include <iostream> using namespace std; #define FIBO_VALUES_COUNT 45 unsigned int s_fibonacciValues[FIBO_VALUES_COUNT]; void buildFibonacciArray(); bool isMultiplication(unsigned int number); bool isFibonacci(unsigned int number); int main() { buildFibonacciArray(); int t = 0; cin >> t; for (int i = 0; i < t; i++) { unsigned int number; cin >> number; bool isOk = isMultiplication(number); cout << (isOk ? "TAK" : "NIE") << endl; } return 0; } void buildFibonacciArray() { s_fibonacciValues[0] = 0; s_fibonacciValues[1] = 1; for (int i = 2; i < FIBO_VALUES_COUNT; i++) { s_fibonacciValues[i] = s_fibonacciValues[i - 1] + s_fibonacciValues[i - 2]; } } bool isMultiplication(unsigned int number) { for (int i = 2; i < FIBO_VALUES_COUNT; i++) { if (number % s_fibonacciValues[i] == 0) { int second = number / s_fibonacciValues[i]; if (isFibonacci(second)) return true; } } return false; } bool isFibonacci(unsigned int number) { for (unsigned int i = 2; i < FIBO_VALUES_COUNT; i++) { if (number == s_fibonacciValues[i]) return true; } 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 | #include <iostream> using namespace std; #define FIBO_VALUES_COUNT 45 unsigned int s_fibonacciValues[FIBO_VALUES_COUNT]; void buildFibonacciArray(); bool isMultiplication(unsigned int number); bool isFibonacci(unsigned int number); int main() { buildFibonacciArray(); int t = 0; cin >> t; for (int i = 0; i < t; i++) { unsigned int number; cin >> number; bool isOk = isMultiplication(number); cout << (isOk ? "TAK" : "NIE") << endl; } return 0; } void buildFibonacciArray() { s_fibonacciValues[0] = 0; s_fibonacciValues[1] = 1; for (int i = 2; i < FIBO_VALUES_COUNT; i++) { s_fibonacciValues[i] = s_fibonacciValues[i - 1] + s_fibonacciValues[i - 2]; } } bool isMultiplication(unsigned int number) { for (int i = 2; i < FIBO_VALUES_COUNT; i++) { if (number % s_fibonacciValues[i] == 0) { int second = number / s_fibonacciValues[i]; if (isFibonacci(second)) return true; } } return false; } bool isFibonacci(unsigned int number) { for (unsigned int i = 2; i < FIBO_VALUES_COUNT; i++) { if (number == s_fibonacciValues[i]) return true; } return false; } |