```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 ``` ```#include #include #include using namespace std; // 数列クラス class Nums { protected: vector Elems; public: Nums(const unsigned int n) { Set(n); } void Set(const unsigned int n) { for (unsigned int i=Elems.size(); i<=n; i++) { Push(i); } } virtual void Push(unsigned int i) {}; int operator[](unsigned int k) { if (k >= Elems.size()) { Set(k); } return Elems[k]; } }; // Fibonacci数列 class ANums : public Nums { public: ANums() : Nums(10) { Elems.push_back(1); Elems.push_back(1); } void Push(unsigned int i) { Elems.push_back(Elems[i-1] + Elems[i-2]); } }; // 数列b class BNums : public Nums { private: ANums A; public: BNums(unsigned int m) : Nums(10), A() { Elems.push_back(m-1); } void Push(unsigned int i) { Elems.push_back(static_cast(ceil(static_cast(Elems[i-1]) * A[i-1] / (A[i-1] + A[i])))); } }; // 数列c class CNums : public Nums { private: BNums B; public: CNums(unsigned int m) : Nums(10), B(m) { Elems.push_back(m-1); } void Push(unsigned int i) { Elems.push_back(Elems[i-1] + ((i%2)?-1:1)*(B[i] - 1)); } }; int main() { const int num = 7110; // 数列cを定義 CNums c(num); // 収束するまで計算 int i; for (i=1; c[i] != c[i-1]; i++); // 書き出し int a = c[i], b = num, k = 0; while (a > 0 && b > 0) { if (k%2) { cout << a << endl; a -= b; } else { cout << b << endl; b -= a; } k++; } return 0; } ```
 ```1 2 3 4 5 6 7 8 9 10 11 12 ``` ```7110 4394 2716 1678 1038 640 398 242 156 86 70 16 ```