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
#include <bits/stdc++.h>
#define ii pair<int, int>
#define pv pair<vector<ii>, int>
#define ff first
#define ss second
using namespace std;

map<int, pv> m;

pv joim(ii a, pv b) {
  vector<ii> v(b.ss);
  v[0] = a;
  for(int i = 0; i < b.ss-1; i++) {
    v[i+1] = {(b.ff[i].ff == -1 ? -1 : b.ff[i].ff+1), (b.ff[i].ss == -1 ? -1 : b.ff[i].ss+1)};
  }
  return {v, b.ss+1};
}

pv join(pv a, pv b) {
  vector<ii> v(a.ss + b.ss - 2);
  for(int i = 0; i < a.ss-1; i++) {
    v[i] = a.ff[i];
  }
  for(int i = 0; i < b.ss-1; i++) {
    v[i+a.ss-1] = {(b.ff[i].ff == -1 ? -1 : b.ff[i].ff+a.ss-1), (b.ff[i].ss == -1 ? -1 : b.ff[i].ss+a.ss-1)};
  }
  return {v, a.ss+b.ss-1};
}

pv get(int k) {
  if(m[k].ss > 0) return m[k];

  for(int i = 2; i*i <= k; i++) {
    if(k % i != 0) continue;
    return m[k] = join(get(i), get(k/i));
  }
  pv x = get(k-1);
  return m[k] = joim({2, x.ss+1}, x);
}

int main() {

  int k;
  scanf("%d", &k);

  m[2] = {{{2, 3}, {3, -1}}, 3};

  pv x = get(k);

  printf("%d\n", x.ss);
  for(int i = 0; i < x.ss-1; i++) {
    printf("%d %d\n", x.ff[i].ff, x.ff[i].ss);
  }
  printf("-1 -1");

}