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

constexpr int nax = 100, kax = 1e9, logg = 32;

int k, tab[logg];
vector< int > gr[nax + 1];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> k;

    int pt = 3;
    for (int _ = logg - 1; _ >= 0; --_, pt += 2) {
        gr[pt - 1].push_back(pt);
        gr[pt - 1].push_back(pt + 1);
        gr[pt].push_back(pt + 1);
        tab[_] = pt + 1;
    }

    gr[pt - 1].push_back(nax);

    cerr << pt << '\n';

    ++pt;

    gr[1].push_back(pt);
    for (int _ = 0; _ < logg; ++_, ++pt) {
        if (_ != 0)
            gr[pt - 1].push_back(pt);
        if (k & (1 << _))
            gr[pt].push_back(tab[_]);
    }

    cerr << pt << '\n';

    cout << nax << '\n';
    for (int i = 1; i <= nax; ++i) {
        //cout << i << ": ";
        for (int j = 0; j < 2; ++j)
            cout << (j < gr[i].size()? gr[i][j] : -1) << ' ';
        cout << '\n';
    }
}