#include<iostream> #include<vector> using namespace std; int main() { vector<long long>numery; long long j; long long r; long long k; long long Fibonacci[44]; Fibonacci[0] = 1; Fibonacci[1] = 1; Fibonacci[2] = 2; Fibonacci[3] = 3; Fibonacci[4] = 5; Fibonacci[5] = 8; Fibonacci[6] = 13; Fibonacci[7] = 21; Fibonacci[8] = 34; Fibonacci[9] = 55; Fibonacci[10] = 89; Fibonacci[11] = 144; Fibonacci[12] = 233; Fibonacci[13] = 377; Fibonacci[14] = 610; Fibonacci[15] = 987; Fibonacci[16] = 1597; Fibonacci[17] = 2584; Fibonacci[18] = 4181; Fibonacci[19] = 6765; Fibonacci[20] = 10946; Fibonacci[21] = 17711; Fibonacci[22] = 28657; Fibonacci[23] = 46368; Fibonacci[24] = 75025; Fibonacci[25] = 121393; Fibonacci[26] = 196418; Fibonacci[27] = 317811; Fibonacci[28] = 514229; Fibonacci[29] = 832040; Fibonacci[30] = 1346269; Fibonacci[31] = 2178309; Fibonacci[32] = 3524578; Fibonacci[33] = 5702887; Fibonacci[34] = 9227465; Fibonacci[35] = 14930352; Fibonacci[36] = 24157817; Fibonacci[37] = 39088169; Fibonacci[38] = 63245986; Fibonacci[39] = 102334155; Fibonacci[40] = 165580141; Fibonacci[41] = 267914296; Fibonacci[42] = 433494437; Fibonacci[43] = 701408733; cin >> k; for (int i = 43; i > 0; i--) { if (Fibonacci[i] <= k) { k = k - Fibonacci[i]; numery.push_back(i); } } if (numery[0] == 1) { cout << "2" << endl; cout << "2 -1" << endl; cout << "-1 -1"; } else { k = (numery[0] * 2) - 1; if (numery[numery.size() - 1] == 1) { k++; j = numery.size() - 2; } else j = numery.size() - 1; cout << k << endl; if (k % 2 == 0) { cout << k <<" -1"<< endl; cout << "3 4" << endl; r = 1; } else { cout << "2 3" << endl; r = 0; } for (int i = 2+r; i < k-1; i++) { if ((i-r) % 2 == 0) cout << i+1 << " " << i + 3 << endl; else { if (((i-r)+1)/2 == numery[j]) { cout << i + 1 << " " << k << endl; j--; } else cout << i +1 << " -1" << endl; } } cout << k <<" -1"<< endl; cout << "-1 -1"; } numery.clear(); 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 | #include<iostream> #include<vector> using namespace std; int main() { vector<long long>numery; long long j; long long r; long long k; long long Fibonacci[44]; Fibonacci[0] = 1; Fibonacci[1] = 1; Fibonacci[2] = 2; Fibonacci[3] = 3; Fibonacci[4] = 5; Fibonacci[5] = 8; Fibonacci[6] = 13; Fibonacci[7] = 21; Fibonacci[8] = 34; Fibonacci[9] = 55; Fibonacci[10] = 89; Fibonacci[11] = 144; Fibonacci[12] = 233; Fibonacci[13] = 377; Fibonacci[14] = 610; Fibonacci[15] = 987; Fibonacci[16] = 1597; Fibonacci[17] = 2584; Fibonacci[18] = 4181; Fibonacci[19] = 6765; Fibonacci[20] = 10946; Fibonacci[21] = 17711; Fibonacci[22] = 28657; Fibonacci[23] = 46368; Fibonacci[24] = 75025; Fibonacci[25] = 121393; Fibonacci[26] = 196418; Fibonacci[27] = 317811; Fibonacci[28] = 514229; Fibonacci[29] = 832040; Fibonacci[30] = 1346269; Fibonacci[31] = 2178309; Fibonacci[32] = 3524578; Fibonacci[33] = 5702887; Fibonacci[34] = 9227465; Fibonacci[35] = 14930352; Fibonacci[36] = 24157817; Fibonacci[37] = 39088169; Fibonacci[38] = 63245986; Fibonacci[39] = 102334155; Fibonacci[40] = 165580141; Fibonacci[41] = 267914296; Fibonacci[42] = 433494437; Fibonacci[43] = 701408733; cin >> k; for (int i = 43; i > 0; i--) { if (Fibonacci[i] <= k) { k = k - Fibonacci[i]; numery.push_back(i); } } if (numery[0] == 1) { cout << "2" << endl; cout << "2 -1" << endl; cout << "-1 -1"; } else { k = (numery[0] * 2) - 1; if (numery[numery.size() - 1] == 1) { k++; j = numery.size() - 2; } else j = numery.size() - 1; cout << k << endl; if (k % 2 == 0) { cout << k <<" -1"<< endl; cout << "3 4" << endl; r = 1; } else { cout << "2 3" << endl; r = 0; } for (int i = 2+r; i < k-1; i++) { if ((i-r) % 2 == 0) cout << i+1 << " " << i + 3 << endl; else { if (((i-r)+1)/2 == numery[j]) { cout << i + 1 << " " << k << endl; j--; } else cout << i +1 << " -1" << endl; } } cout << k <<" -1"<< endl; cout << "-1 -1"; } numery.clear(); return 0; } |