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
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <stack>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	int n, logN, m;
	int edges1[100];
	int edges2[100];
	
	cin >> n;
	
	stack<int> bytes;	
	while (n > 0) {
		bytes.push(n % 2);
		n /= 2;
	}
	
	logN = bytes.size() - 1;
	m = logN * 3 + 2;
	
	for (int i = 0; i < m; ++i) {
		edges1[i] = i + 1;
		edges2[i] = -1;
	}
	edges1[m - 1] = -1;
	
	for (int i = logN + 1; i < m - 1; i += 2) {
		edges2[i] = i + 2;
	}
	
	bytes.pop();
	int fromV = 1;
	int toV = logN + 3;
	
	while (!bytes.empty()) {
		int doSth = bytes.top();
		bytes.pop();
		
		if (doSth) {
			edges2[fromV] = toV;
		}
		
		++fromV;
		toV += 2;
	}
	
	cout << m << endl;
	for (int i = 0; i < m; ++i) {
		if (edges1[i] >= 0) {
			++edges1[i];
		}
		if (edges2[i] >= 0) {
			++edges2[i];
		}
		
		cout << edges1[i] << " " << edges2[i] << endl;
	}
	
	
	
	
	return 0;
}