#include <iostream> #include <math.h> using namespace std; // A utility function that returns true if x is perfect square bool isPerfectSquare(int x); // Returns true if n is a Fibinacci Number, else false bool isFibonacci(int n); int main() { int t; cin>>t; for (int i = 0; i < t; ++i) { int n; cin>>n; int divisorA, divisorB,divisorMAX; divisorMAX = sqrt(n); int j; for (j = 1; j <= divisorMAX; ++j) { if (n%j) continue; divisorA = j; divisorB = n/divisorA; if(isFibonacci(divisorA)&&isFibonacci(divisorB)) { cout<<"TAK"<<endl; break; } } if(j>divisorMAX)cout<<"NIE"<<endl; } } bool isFibonacci(int n) { // n is Fibinacci if one of 5*n*n + 4 or 5*n*n - 4 or both // is a perferct square return isPerfectSquare(5*n*n + 4) || isPerfectSquare(5*n*n - 4); } bool isPerfectSquare(int x) { int s = sqrt(x); return (s*s == x); }
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 <math.h> using namespace std; // A utility function that returns true if x is perfect square bool isPerfectSquare(int x); // Returns true if n is a Fibinacci Number, else false bool isFibonacci(int n); int main() { int t; cin>>t; for (int i = 0; i < t; ++i) { int n; cin>>n; int divisorA, divisorB,divisorMAX; divisorMAX = sqrt(n); int j; for (j = 1; j <= divisorMAX; ++j) { if (n%j) continue; divisorA = j; divisorB = n/divisorA; if(isFibonacci(divisorA)&&isFibonacci(divisorB)) { cout<<"TAK"<<endl; break; } } if(j>divisorMAX)cout<<"NIE"<<endl; } } bool isFibonacci(int n) { // n is Fibinacci if one of 5*n*n + 4 or 5*n*n - 4 or both // is a perferct square return isPerfectSquare(5*n*n + 4) || isPerfectSquare(5*n*n - 4); } bool isPerfectSquare(int x) { int s = sqrt(x); return (s*s == x); } |