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 <iostream>

//#include <chrono> 
//using namespace std::chrono; 

using namespace std;

int main()
{
    long long k;
    int graf[100][2], n, g;

//    auto start = high_resolution_clock::now();

    cin >> k;
    if (k == 1) {
        cout << "2" << endl;
        cout << "2 -1" << endl;
        cout << "-1 -1" << endl;
        return 0;
    }

    g = 1;
    while (k > 1) {
        graf[g][0] = g + 1; graf[g][1] = g + 2;
        graf[++g][0] = (k % 2 == 0) ? -1 : 0; graf[g][1] = g + 1;
        g++; k = k / 2;
    }
    graf[g][0] = g + 1; graf[g][1] = -1;
    n = g + 1;

    cout << n << endl;
    for (g = 1; g < n; g++) {
        cout << (graf[g][0] != 0 ? graf[g][0] : n) << " ";
        cout << (graf[g][1] != 0 ? graf[g][1] : n) << endl;
    }
    cout << "-1 -1" << endl;

//    auto stop = high_resolution_clock::now(); 
//    auto duration = duration_cast<microseconds>(stop - start);
//    cout << endl << "Timer=" << duration.count() << endl;

    return 0;
}