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
#include <cstdio>
#include <iostream>

using namespace std;

int t[35];
// k - pow of 2
int find_k(int n){
    int i = 0;
    while(n >= t[i]){
        i++;
    }
    return i;
}

void print_edges(int a= -1, int b= -1){
    cout << a << " " << b << endl;
}

int main() {
    //ios::sync_with_stdio(false);
	int n;
	t[0] = 1;
	for(int i = 1; i < 31; i++){
        t[i] = t[i-1] * 2;
	}
	cin >> n;
	if(n == 1){
        cout << 2 << endl;
        print_edges(2);
        print_edges();
	}
	else{
        int k = find_k(n);
        cout << 3* k -1<< endl;
        int rest = n - t[k-1];

        if(rest > 0) print_edges(k, 2*k);
        else print_edges(k);
        print_edges(3*k-1, k+1);
        for(int i=0; i<k-2; i++)print_edges(i+2, i+ 2 +k);
        print_edges(3*k-1);
        for(int i=0; i<k-2; i++)print_edges(i+2);
        for(int i = 0; i< k-1; i++){
            if(rest > 0){
                int local_k = find_k(rest);
                if(t[local_k - 1] == 1)print_edges(3*k-1);
                else print_edges(local_k, 2*k + i+1);
                rest = rest - t[local_k - 1];
            }
            else{print_edges();}
        }
        print_edges();
	}
}