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
#include<stdio.h>
int rv[101];
int main() {
    int n;
    int x = scanf("%d\n", &n);
    if (x != 1) return 1;
    if (n==1) {
        printf("2\n2 -1\n-1 -1\n");
        return 0;
    }
    int count = 1;
    int len = 0;
    while (n > 1) {
        rv[len++] = n&1;
        //printf("mam %d bo %d\n", rv[len-1], n);
        if (n&1) {
            n--;
            count++;
        } else {
            n >>=1;
            count += 2;
        }
    }
    printf("%d\n", count);
    int pos = 1;
    for(int i =0;i<len;i++) {
        if (rv[i]) {
            printf("%d %d\n", pos+1, count);
            pos++;
        } else {
            printf("%d %d\n", pos+1, pos+2);
            printf("%d %d\n", pos+2, -1);
            pos+=2;
        }
    }
    printf("%d %d\n", -1, -1);      
    return 0;
}