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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include<iostream>
#include<vector>

using namespace std;
int wolny(int a, vector<vector<int>> &Edges)
{
    for(int i=a+1; i<101; i++)
        if(Edges[i][0]==-1&&Edges[i][1]==-1)
            if(Edges[i][2]==-1)
                return i;
}
int Dzielnik(int n)
{
    for(int i=2; i*i<=n; i++)
    {
        if(n%i==0)
        return i;
    }
    return 0;
}
int Graf(int E, vector<vector<int>> &Edges, int point, int koniec)
{
    int t=E;
    int temp;
    int counter = 0;
    if(E==1)
    {
        Edges[point][0]=koniec;
        return 1;
    }
    if(E==2)
    {
        Edges[point][0]=koniec;
        temp = wolny(point, Edges);
        Edges[point][1]=temp;
        Edges[temp][0]=koniec;
        return 2;
    }
    while(Dzielnik(E)!=0)
    {
        int koniec_temp = wolny(point, Edges);
        Edges[koniec_temp][2]=0;
        counter+=Graf(Dzielnik(E), Edges, point, koniec_temp);
        E/=Dzielnik(E);
        point=koniec_temp;
    }
    if(E==1)
    {
        Edges[point][0]=koniec;
        //N[t]=counter+1;
        return counter+1;
    }
    if(E==2)
    {
        temp=wolny(point, Edges);
        Edges[point][0]=koniec;
        Edges[point][1]=temp;
        Edges[temp][0]=koniec;
        //N[t]=counter+2;
        return counter+2;
    }
    Edges[point][0]=koniec;
    temp = wolny(point, Edges);
    Edges[point][1]=temp;
    point = temp;
    counter+=Graf(E-1, Edges, point, koniec);
    point=wolny(point, Edges);
    counter+=1;
    //N[t]=counter;
    return counter;


}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin >> k;
    int point=1;
    vector<vector<int>> Edges(101, vector<int> (3, -1));
    int counter=Graf(k, Edges, point, -2)+1;
    cout << counter << "\n";
    for(int i=1; i<=counter; i++)
    {
        if(Edges[i][0]==-2)
            cout << counter << ' ';
        else
            cout << Edges[i][0] << ' ';
        cout << Edges[i][1] << "\n";
    }
    return 0;

}