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
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
using PII = pair<int, int>;

int main()
{
	int k;

	cin >> k;

	vector<PII> graph;
	graph.push_back(make_pair(-2, -2));

	int cur = 0;

	while (k > 1)
	{
		if (k & 1)
			graph.push_back(make_pair(cur + 2, 1000));
		else
			graph.push_back(make_pair(cur + 2, -2));

		graph.push_back(make_pair(-2, -2));
		graph[cur].first = cur + 1;
		graph[cur].second = cur + 2;

		cur += 2;
		k >>= 1;
	}

	for (int i = 0; i < graph.size(); ++i)
	{
		if (graph[i].first == 1000)
			graph[i].first = graph.size();

		if (graph[i].second == 1000)
			graph[i].second = graph.size();
	}

	graph[cur].first = graph.size();
	graph.push_back(make_pair(-2, -2));

	cout << graph.size() << endl;

	for (int i = 0; i < graph.size(); ++i)
	{
		cout << graph[i].first + 1 << " " << graph[i].second + 1 << endl;
	}

	return 0;
}