#include <iostream>
#include <cmath>
using namespace std;
const long long x=46;
long long f[x];
void fibo(){
f[0]=0;
f[1]=1;
for(int i=2; i<x; i++){f[i]=f[i-2]+f[i-1];}
}
bool czy(long long n){
int i=0;
while(f[i]<=n){
if(f[i]==n){return true;}
else{i++;}
}
return false;
}
bool podziel(long long n){
double a=sqrt(n);
for(int i=2; i<=a; i++){
if( (czy(i)==true) && (n%i==0)){
if( czy(n/i)==true){return true;}}
}
return false;
}
int main (){
fibo();
int t;
long long n;
cin >>t;
for(int i=0; i<t; i++){
cin >>n;
if(czy (n)==true||podziel (n)==true){cout<<"TAK"<<endl;}
else{cout<<"NIE"<<endl;}
}
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 | #include <iostream> #include <cmath> using namespace std; const long long x=46; long long f[x]; void fibo(){ f[0]=0; f[1]=1; for(int i=2; i<x; i++){f[i]=f[i-2]+f[i-1];} } bool czy(long long n){ int i=0; while(f[i]<=n){ if(f[i]==n){return true;} else{i++;} } return false; } bool podziel(long long n){ double a=sqrt(n); for(int i=2; i<=a; i++){ if( (czy(i)==true) && (n%i==0)){ if( czy(n/i)==true){return true;}} } return false; } int main (){ fibo(); int t; long long n; cin >>t; for(int i=0; i<t; i++){ cin >>n; if(czy (n)==true||podziel (n)==true){cout<<"TAK"<<endl;} else{cout<<"NIE"<<endl;} } return 0; } |
English