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
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int k; cin >> k;
  int n = (int)log2(k) + 5;
  vector<pair<int,int>> tpsort(n);
  const int R = 1 << 30;
  const int X = -2;
  tpsort[0] = {1, 2};

  int i = 1;
  while (true) {
    if (k == 1) {
      tpsort[i-1] = {X, R};
      break;
    }
    if (k%2) {
      tpsort[i] = {i+1, R};
      tpsort[i+1] = {i+2, i+3};
    }
    else {
      tpsort[i] = {i+1, X};
      tpsort[i+1] = {i+2, i+3};
    }
    k /= 2;
    i += 2;
  }
  tpsort[i] = {X, X};

  cout << i+1 << '\n';
  for (int j = 0; j <= i; ++j) {
    auto &p = tpsort[j];
    cout << p.first+1 << ' ';
    if (p.second == R)
      cout << i+1 << '\n';
    else
      cout << p.second+1 << '\n';
  }
}