#include<cstdio> using namespace std; int main(){ int k; scanf("%d", &k); int act_node = 1; int n = 2; int a = k; while(a > 1){ if (a % 2 == 1) a = ( a -1) /2; else a /= 2; n += 3; } printf("%d\n", n); while (k > 1){ if(k % 2 == 1){ k = (k - 1 ) /2; printf("%d %d\n", act_node+1, act_node+2); printf("%d %d\n", n, act_node+3); printf("%d -1\n", act_node+3); } /*else if( k % 3 == 0){ k /= 3; printf("%d %d\n", act_node+1, act_node+2); printf("%d %d\n", act_node +2, act_node+3); printf("%d -1\n", act_node+3); }*/ else{ k /= 2; printf("%d %d\n", act_node+1, act_node+2); printf("%d -1\n", act_node+3); printf("%d -1\n", act_node+3); } act_node += 3; } printf("-1 %d\n", n); printf("-1 -1\n"); return 0; }
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 | #include<cstdio> using namespace std; int main(){ int k; scanf("%d", &k); int act_node = 1; int n = 2; int a = k; while(a > 1){ if (a % 2 == 1) a = ( a -1) /2; else a /= 2; n += 3; } printf("%d\n", n); while (k > 1){ if(k % 2 == 1){ k = (k - 1 ) /2; printf("%d %d\n", act_node+1, act_node+2); printf("%d %d\n", n, act_node+3); printf("%d -1\n", act_node+3); } /*else if( k % 3 == 0){ k /= 3; printf("%d %d\n", act_node+1, act_node+2); printf("%d %d\n", act_node +2, act_node+3); printf("%d -1\n", act_node+3); }*/ else{ k /= 2; printf("%d %d\n", act_node+1, act_node+2); printf("%d -1\n", act_node+3); printf("%d -1\n", act_node+3); } act_node += 3; } printf("-1 %d\n", n); printf("-1 -1\n"); return 0; } |