#include <stdio.h> #include <iostream> using namespace std; const int MAXARR=43; long fibArr[MAXARR]; void fillArr(){ int nr=0; fibArr[nr++]=1; fibArr[nr++]=2; while(nr<MAXARR){ fibArr[nr]=fibArr[nr-1]+fibArr[nr-2]; nr++; } } void showArr(){ for(int i=0;i<MAXARR;i++) cout << i << ')' << fibArr[i] << endl; } bool isValue(long value) { for(int i=0;i<MAXARR;i++) if(value==fibArr[i]) return true; return false; } bool isOK(long n){ if(n==0 || n==1) return true; int i=1; long rest; while(i<MAXARR){ if(n%fibArr[i]==0){ rest=n/fibArr[i]; if(isValue(rest)) return true; } i++; } return false; } void showAnswer(long n){ if(isOK(n)) cout << "TAK" << endl; else cout << "NIE" << endl; } int main(){ fillArr(); // showArr(); int howMany; cin >> howMany; long value; for(int i=0;i<howMany;i++){ cin >> value; showAnswer(value); } // int x; // cin >> x; 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 | #include <stdio.h> #include <iostream> using namespace std; const int MAXARR=43; long fibArr[MAXARR]; void fillArr(){ int nr=0; fibArr[nr++]=1; fibArr[nr++]=2; while(nr<MAXARR){ fibArr[nr]=fibArr[nr-1]+fibArr[nr-2]; nr++; } } void showArr(){ for(int i=0;i<MAXARR;i++) cout << i << ')' << fibArr[i] << endl; } bool isValue(long value) { for(int i=0;i<MAXARR;i++) if(value==fibArr[i]) return true; return false; } bool isOK(long n){ if(n==0 || n==1) return true; int i=1; long rest; while(i<MAXARR){ if(n%fibArr[i]==0){ rest=n/fibArr[i]; if(isValue(rest)) return true; } i++; } return false; } void showAnswer(long n){ if(isOK(n)) cout << "TAK" << endl; else cout << "NIE" << endl; } int main(){ fillArr(); // showArr(); int howMany; cin >> howMany; long value; for(int i=0;i<howMany;i++){ cin >> value; showAnswer(value); } // int x; // cin >> x; return 0; } |