//============================================================================ // Name : Fibonacci.cpp // Author : Tytus Bierwiaczonek // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <stdio.h> #include <stdlib.h> #include <math.h> using namespace std; int main() { unsigned int i, maxi, j, n, fib[10000], m(0); scanf("%d", &n); unsigned int input[10]; for (i = 0; i < n; i++) { scanf("%d", &input[i]); // print m = max(input[i], m); } fib[0] = 0; fib[1] = 1; for (i = 2; fib[i - 1] < m; ++i) { fib[i] = fib[i - 1] + fib[i - 2]; } maxi = i - 1; for (j = 0; j < n; ++j) { if (0 == input[j]) { printf("TAK\n"); continue; } int t = (unsigned int) sqrt(input[j]); // printf("t = %d\n", t); bool tak = false; for (i = 1; fib[i] <= t; ++i) { if (0 == input[j] % fib[i]) { unsigned int w = input[j] / fib[i]; unsigned int k = lower_bound(fib, fib + maxi, w) - fib; // printf("%d %d\n", k, w); if (fib[k] == w) { tak = true; break; } } } if (tak) { 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 60 61 62 63 64 65 66 67 68 69 70 71 72 | //============================================================================ // Name : Fibonacci.cpp // Author : Tytus Bierwiaczonek // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <stdio.h> #include <stdlib.h> #include <math.h> using namespace std; int main() { unsigned int i, maxi, j, n, fib[10000], m(0); scanf("%d", &n); unsigned int input[10]; for (i = 0; i < n; i++) { scanf("%d", &input[i]); // print m = max(input[i], m); } fib[0] = 0; fib[1] = 1; for (i = 2; fib[i - 1] < m; ++i) { fib[i] = fib[i - 1] + fib[i - 2]; } maxi = i - 1; for (j = 0; j < n; ++j) { if (0 == input[j]) { printf("TAK\n"); continue; } int t = (unsigned int) sqrt(input[j]); // printf("t = %d\n", t); bool tak = false; for (i = 1; fib[i] <= t; ++i) { if (0 == input[j] % fib[i]) { unsigned int w = input[j] / fib[i]; unsigned int k = lower_bound(fib, fib + maxi, w) - fib; // printf("%d %d\n", k, w); if (fib[k] == w) { tak = true; break; } } } if (tak) { printf("TAK\n"); } else { printf("NIE\n"); } } return 0; } |