#include <bits/stdc++.h>
using namespace std;
long long tab[50];
long long f(int x){
if (x == 1) return tab[x] = 1;
if (x == 2) return tab[x] = 1;
if (tab[x] != 0) return tab[x];
return tab[x] = f(x - 1) + f(x - 2);
}
vector <int> pozycje;
int main (){
long long x = f(46);
long long k;
cin >> k;
// for (int i = 0; i < 10; i ++) cout << tab[i] << " ";
// cout << "\n";
int pozycja = lower_bound(tab, tab + 45, k) - tab;
if (tab[pozycja] == k){
if (k == 1) pozycja ++;
// pozycja ++;
cout << pozycja << "\n";
for (int i = 1; i < pozycja - 1; i ++){
cout << i + 1 << " " << i + 2 << "\n";
}
cout << pozycja << " -1\n";
cout << "-1 -1\n";
return 0;
}
pozycja --;
// cout << tab[pozycja] << "\n";
long long nk = k - tab[pozycja];
int ile = 0;
while (nk > 0){
int pozycja_2 = lower_bound(tab, tab + pozycja, nk) - tab;
if (tab[pozycja_2] != nk) pozycja_2 --;
nk -= tab[pozycja_2];
pozycje.push_back(pozycja_2);
ile ++;
}
cout << pozycja + ile << "\n";
int j = 1;
while (pozycje.size()){
int poz = pozycje[pozycje.size() - 1];
pozycje.pop_back();
cout << j + 1 << " " << pozycja + 1 + ile - poz << "\n";
j ++;
}
for (int i = 1; i < pozycja - 1; i ++){
cout << i + 1 + ile << " " << i + 2 + ile << "\n";
}
cout << pozycja + ile << " -1\n";
cout << "-1 -1\n";
// cout << nk << "\n";
// int pozycja_2 = lower_bound(tab, tab + pozycja, nk) - tab;
// if (tab[pozycja_2] != nk) pozycja_2 --;
// cout << pozycja_2 << " " << tab[pozycja_2] << "\n";
// cout << "to ma dzialac\n";
// cout << pozycja + 1 << "\n";
// cout << 2 << " " << pozycja + 1 + 1 - pozycja_2 << "\n";
// for (int i = 1; i < pozycja - 1; i ++){
// cout << i + 1 + 1 << " " << i + 2 + 1<< "\n";
// }
// cout << pozycja + 1 << " -1\n";
// cout << "-1 -1\n";
}
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 | #include <bits/stdc++.h> using namespace std; long long tab[50]; long long f(int x){ if (x == 1) return tab[x] = 1; if (x == 2) return tab[x] = 1; if (tab[x] != 0) return tab[x]; return tab[x] = f(x - 1) + f(x - 2); } vector <int> pozycje; int main (){ long long x = f(46); long long k; cin >> k; // for (int i = 0; i < 10; i ++) cout << tab[i] << " "; // cout << "\n"; int pozycja = lower_bound(tab, tab + 45, k) - tab; if (tab[pozycja] == k){ if (k == 1) pozycja ++; // pozycja ++; cout << pozycja << "\n"; for (int i = 1; i < pozycja - 1; i ++){ cout << i + 1 << " " << i + 2 << "\n"; } cout << pozycja << " -1\n"; cout << "-1 -1\n"; return 0; } pozycja --; // cout << tab[pozycja] << "\n"; long long nk = k - tab[pozycja]; int ile = 0; while (nk > 0){ int pozycja_2 = lower_bound(tab, tab + pozycja, nk) - tab; if (tab[pozycja_2] != nk) pozycja_2 --; nk -= tab[pozycja_2]; pozycje.push_back(pozycja_2); ile ++; } cout << pozycja + ile << "\n"; int j = 1; while (pozycje.size()){ int poz = pozycje[pozycje.size() - 1]; pozycje.pop_back(); cout << j + 1 << " " << pozycja + 1 + ile - poz << "\n"; j ++; } for (int i = 1; i < pozycja - 1; i ++){ cout << i + 1 + ile << " " << i + 2 + ile << "\n"; } cout << pozycja + ile << " -1\n"; cout << "-1 -1\n"; // cout << nk << "\n"; // int pozycja_2 = lower_bound(tab, tab + pozycja, nk) - tab; // if (tab[pozycja_2] != nk) pozycja_2 --; // cout << pozycja_2 << " " << tab[pozycja_2] << "\n"; // cout << "to ma dzialac\n"; // cout << pozycja + 1 << "\n"; // cout << 2 << " " << pozycja + 1 + 1 - pozycja_2 << "\n"; // for (int i = 1; i < pozycja - 1; i ++){ // cout << i + 1 + 1 << " " << i + 2 + 1<< "\n"; // } // cout << pozycja + 1 << " -1\n"; // cout << "-1 -1\n"; } |
English