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

vector<pair<int, int>> output;
stack<int> rests;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int K = 3;
    cin >> K;
    int len = 2;
    while (K >= 2)
    {
        len += 2 + K % 2;
        rests.push(K % 2);
        K = K / 2;
    }
    output.resize(len + 1, pair<int, int>(-1, -1));
    output[len - 1] = pair<int, int>(-1, len);
    int l = len - 1;
    while (!rests.empty())
    {
        l--;
        output[l] = pair<int, int>(-1, l + 1);
        l--;
        output[l] = pair<int, int>(l + 1, l + 2);
        int rest = rests.top();
        rests.pop();
        if (rest)
        {
            l--;
            output[l] = pair<int, int>(l + 1, len);
        }
    }
    cout << output.size() - 1 << endl;
    for (int i = 1; i < output.size(); ++i)
        cout << output[i].first   << " " << output[i].second << endl;

    return 0;
}