#include <iostream> #include <stdio.h> using namespace std; int main() { int a, n; int fib[50]; fib[0] = 1; fib[1] = 1; int k=1; while (fib[k] < 1000000000) { fib[k+1] = fib[k] + fib[k-1]; k++; } scanf("%d",&n); for (int i=0; i<n; i++) { scanf("%d",&a); if (a == 0) { printf("TAK\n"); continue; } bool czyTak = false; for (int j=0; j<k; j++) { if (a%fib[j] == 0) { int b = a/fib[j]; for (int m=j; m<k; m++) if (fib[m] == b) { czyTak = true; break; } } } if (czyTak) printf("TAK\n"); else printf("NIE\n"); } }
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> #include <stdio.h> using namespace std; int main() { int a, n; int fib[50]; fib[0] = 1; fib[1] = 1; int k=1; while (fib[k] < 1000000000) { fib[k+1] = fib[k] + fib[k-1]; k++; } scanf("%d",&n); for (int i=0; i<n; i++) { scanf("%d",&a); if (a == 0) { printf("TAK\n"); continue; } bool czyTak = false; for (int j=0; j<k; j++) { if (a%fib[j] == 0) { int b = a/fib[j]; for (int m=j; m<k; m++) if (fib[m] == b) { czyTak = true; break; } } } if (czyTak) printf("TAK\n"); else printf("NIE\n"); } } |