#include <iostream> int maxF = 41; int* pamietnik = new int[maxF]; int liczFibbonaci2(int n){ if (pamietnik[n] != -1)return pamietnik[n]; else { int tmp; if (n == 0) tmp = 0; else if (n == 1) tmp = 1; else tmp = liczFibbonaci2(n - 1) + liczFibbonaci2(n - 2); pamietnik[n] = tmp; return tmp; } } bool sprawdzCzyLiczbaFibbonaciego(int liczba){ bool found = false; for (int i = 0; i < maxF; i++){ if (liczba == pamietnik[i])found= true; } return found; } int wczytane[10] = {}; bool iloczyny[10]; int main(){ for (int i = 0; i < maxF; i++){ pamietnik[i] = -1; liczFibbonaci2(i); } int t; std::cin >> t; for (int i = 0; i < t; i++){ std::cin >> wczytane[i]; } for (int i = 0; i < t; i++){ if (wczytane[i] == 0){ iloczyny[i] = true; continue; } else{ for (int j = 1; j<21; j++){ int l1 = pamietnik[j]; if (wczytane[i] % l1 == 0){ int l2 = wczytane[i] / l1; if (sprawdzCzyLiczbaFibbonaciego(l2)){ iloczyny[i] = true; break; } } } } } for (int i = 0; i < t; i++){ if (iloczyny[i]==0) std::cout << "NIE" << "\n"; else std::cout << "TAK" << "\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 51 52 53 54 55 56 57 58 59 60 | #include <iostream> int maxF = 41; int* pamietnik = new int[maxF]; int liczFibbonaci2(int n){ if (pamietnik[n] != -1)return pamietnik[n]; else { int tmp; if (n == 0) tmp = 0; else if (n == 1) tmp = 1; else tmp = liczFibbonaci2(n - 1) + liczFibbonaci2(n - 2); pamietnik[n] = tmp; return tmp; } } bool sprawdzCzyLiczbaFibbonaciego(int liczba){ bool found = false; for (int i = 0; i < maxF; i++){ if (liczba == pamietnik[i])found= true; } return found; } int wczytane[10] = {}; bool iloczyny[10]; int main(){ for (int i = 0; i < maxF; i++){ pamietnik[i] = -1; liczFibbonaci2(i); } int t; std::cin >> t; for (int i = 0; i < t; i++){ std::cin >> wczytane[i]; } for (int i = 0; i < t; i++){ if (wczytane[i] == 0){ iloczyny[i] = true; continue; } else{ for (int j = 1; j<21; j++){ int l1 = pamietnik[j]; if (wczytane[i] % l1 == 0){ int l2 = wczytane[i] / l1; if (sprawdzCzyLiczbaFibbonaciego(l2)){ iloczyny[i] = true; break; } } } } } for (int i = 0; i < t; i++){ if (iloczyny[i]==0) std::cout << "NIE" << "\n"; else std::cout << "TAK" << "\n"; } return 0; } |