#include <iostream> #include <list> #define FIBARRAYSIZE 50 using namespace std; class fibgen { public: unsigned int current; unsigned int last; unsigned int amount; unsigned int data[FIBARRAYSIZE]; fibgen(){ data[0]=last=0; data[1]=current=1; amount=2; }; bool genNext(void) { current = current +last; last = current-last; amount++; if(amount<FIBARRAYSIZE){ data[amount-1]=current; return true; }else return false; }; unsigned int getAmount(){ return amount; } bool genUntilBigger(unsigned int limit) { while(current<limit) { if(this->genNext()==false) return false; } } bool isFib(unsigned int Number) { int it =1; while(Number>this->data[it]) { it++; } if(Number==data[it]) return true; else return false; } void printData(void) { cout<<endl; cout<<"Amount ="<<amount<<endl<<"MaxFib = "<<data[amount-1]<<endl; } void printFib() { for(int it =0;it<amount;it++) { cout<<"Fib["<<it+1<<"]= "<<this->data[it]<<" \t"; } cout<<endl; } }; class Matter{ public: unsigned int val; bool ans; bool isSolved; std::list <unsigned int> FibDvisor; Matter(){ val = 0; ans = false; isSolved = false; } void setVal(unsigned int Value) { this->val=Value; if((val==0)||(val==1)){ this->ans=true; isSolved=true; }else this->FibDvisor.push_back(val); } void push_Divisor(unsigned int div){ this->FibDvisor.push_back(div); } void check(fibgen &Working) { int it; it=2; unsigned int tmp; while(Working.data[it]<val) { if((val%Working.data[it])==0) if(Working.isFib(val/Working.data[it])) { // cout<<"Val: "<<val<<" Modulo "<<(val%Working.data[it]); // cout<<"Val: "<<val<<" Divider "<<(val/Working.data[it])<<endl; ans=true; isSolved=true; break; }; it++; } } }; int main() { short int t; unsigned int inBuffer; unsigned int FibMax=0; class Matter data[10]; class fibgen gen; cin>>t; for(int mi=0;mi<t;mi++) { cin>>inBuffer; if(inBuffer>FibMax) FibMax=inBuffer; data[mi].setVal(inBuffer); } gen.genUntilBigger(FibMax); for(int mi=0;mi<t;mi++) { data[mi].check(gen); if(data[mi].ans) cout<<"TAK"<<endl; else cout<<"NIE"<<endl; } //gen.printData(); // gen.printFib(); 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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | #include <iostream> #include <list> #define FIBARRAYSIZE 50 using namespace std; class fibgen { public: unsigned int current; unsigned int last; unsigned int amount; unsigned int data[FIBARRAYSIZE]; fibgen(){ data[0]=last=0; data[1]=current=1; amount=2; }; bool genNext(void) { current = current +last; last = current-last; amount++; if(amount<FIBARRAYSIZE){ data[amount-1]=current; return true; }else return false; }; unsigned int getAmount(){ return amount; } bool genUntilBigger(unsigned int limit) { while(current<limit) { if(this->genNext()==false) return false; } } bool isFib(unsigned int Number) { int it =1; while(Number>this->data[it]) { it++; } if(Number==data[it]) return true; else return false; } void printData(void) { cout<<endl; cout<<"Amount ="<<amount<<endl<<"MaxFib = "<<data[amount-1]<<endl; } void printFib() { for(int it =0;it<amount;it++) { cout<<"Fib["<<it+1<<"]= "<<this->data[it]<<" \t"; } cout<<endl; } }; class Matter{ public: unsigned int val; bool ans; bool isSolved; std::list <unsigned int> FibDvisor; Matter(){ val = 0; ans = false; isSolved = false; } void setVal(unsigned int Value) { this->val=Value; if((val==0)||(val==1)){ this->ans=true; isSolved=true; }else this->FibDvisor.push_back(val); } void push_Divisor(unsigned int div){ this->FibDvisor.push_back(div); } void check(fibgen &Working) { int it; it=2; unsigned int tmp; while(Working.data[it]<val) { if((val%Working.data[it])==0) if(Working.isFib(val/Working.data[it])) { // cout<<"Val: "<<val<<" Modulo "<<(val%Working.data[it]); // cout<<"Val: "<<val<<" Divider "<<(val/Working.data[it])<<endl; ans=true; isSolved=true; break; }; it++; } } }; int main() { short int t; unsigned int inBuffer; unsigned int FibMax=0; class Matter data[10]; class fibgen gen; cin>>t; for(int mi=0;mi<t;mi++) { cin>>inBuffer; if(inBuffer>FibMax) FibMax=inBuffer; data[mi].setVal(inBuffer); } gen.genUntilBigger(FibMax); for(int mi=0;mi<t;mi++) { data[mi].check(gen); if(data[mi].ans) cout<<"TAK"<<endl; else cout<<"NIE"<<endl; } //gen.printData(); // gen.printFib(); return 0; }; |