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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <cstdio>

int main()
{
  int k;
  scanf("%d", &k);
  
  int bits[32];
  int b = 0;
  int ones = 0;
  while (k > 0)
  {
    bits[b] = k % 2;
    ones += bits[b];
    k /= 2;
    b++;
  }
  //27
  //1 1 0 1 1
  
  if (b == 1)
  {
    printf("2\n");
    printf("2 -1\n");
    printf("-1 -1");
    return 0;
  }
 
  int n = b - 1 + 2 * b;
  
  printf("%d\n", n);
  
  //(1 2), (1 b * 2)
  printf("2 %d\n", b * 2);
  
  //(2, 3), (2, 4), (4, 5), (4, 6)...
  for (int i = 1; i <= b - 2; i++)
  {
    printf("%d %d\n", 2 * i + 1, 2 * i + 2);
    printf("%d %d\n", 2 * i + 2, -1);
  }
  //1, 2, 3, ... 2 * (b - 2), 2 *(b-2)+1
  // (2 * (b - 2) + 2, n)
  printf("%d %d\n", n, 2 * (b - 2) + 2 + 1);
  // (2 * (b - 2) + 2 + 1, n)
  printf("%d %d\n", n, -1);
  
  // (2 * b,
  int j = 4, l = 2 * b;
  for (int i = b - 2; i >= 0; --i)
  {
    if (i == 0)
    {
      if (bits[i])
      {
        printf("%d %d\n", n, -1);
      }
      else
      {
        printf("%d %d\n", -1, -1);
      }
    }
    else
    {
      if (bits[i])
      {
        printf("%d %d\n", j, l + 1);
      }
      else
      {
        printf("%d %d\n", -1, l + 1);
      }
    }
    l++;
    j += 2;
  }
  printf("-1 -1\n");
  return 0;
}