/* * ilo.cpp * * Created on: May 7, 2014 * Author: michal */ #include <stdio.h> #include <stdlib.h> #include <algorithm> #include <functional> #include <math.h> using namespace std; int N; int K; unsigned int F[102]; bool check (unsigned int K) { int sqrtK = sqrt(K); int i=1; while(i<=sqrtK) { if (K%i == 0) { int j = K/i; bool found = binary_search(F,F+50,i); if (found) { found = binary_search(F,F+50,j); if (found) return true; } } ++i; } return false; } int main() { F[0] = 0; F[1] = 1; for (int x=2;x<=50;++x) F[x] = F[x-2]+F[x-1]; scanf("%d",&N); for(int x=0;x<N;++x) { scanf("%d",&K); if (check(K)) printf("TAK\n"); else printf("NIE\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 | /* * ilo.cpp * * Created on: May 7, 2014 * Author: michal */ #include <stdio.h> #include <stdlib.h> #include <algorithm> #include <functional> #include <math.h> using namespace std; int N; int K; unsigned int F[102]; bool check (unsigned int K) { int sqrtK = sqrt(K); int i=1; while(i<=sqrtK) { if (K%i == 0) { int j = K/i; bool found = binary_search(F,F+50,i); if (found) { found = binary_search(F,F+50,j); if (found) return true; } } ++i; } return false; } int main() { F[0] = 0; F[1] = 1; for (int x=2;x<=50;++x) F[x] = F[x-2]+F[x-1]; scanf("%d",&N); for(int x=0;x<N;++x) { scanf("%d",&K); if (check(K)) printf("TAK\n"); else printf("NIE\n"); } return 0; } |