#include <bits/stdc++.h>
using namespace std;
int edge[101][2];
int main(){
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
for (int i = 1; i <= 100; ++i)
{
edge[i][0] = edge[i][1] = -1;
}
long long k;
cin >> k;
// wierzchołki 1, 2 i 3
edge[99][0] = 100;
edge[98][0] = 100;
edge[98][1] = 99;
long long cur = k;
int cur_v = 1;
while(true){
if(cur == 1){
edge[cur_v][0] = 100;
break;
}
if(cur == 2){
edge[cur_v][0] = 98;
break;
}
if(cur == 3){
edge[cur_v][1] = 99;
edge[cur_v][0] = 98;
break;
}
if(cur >= 4){
if(cur % 2 == 0){
edge[cur_v][0] = cur_v + 1;
edge[cur_v][1] = cur_v + 2;
edge[cur_v + 1][0] = 98;
edge[cur_v + 1][1] = cur_v + 2;
cur_v += 2;
cur = cur / 2 - 1;
}
else{
edge[cur_v][0] = cur_v + 1;
edge[cur_v][1] = cur_v + 2;
edge[cur_v + 1][0] = 99;
edge[cur_v + 1][1] = cur_v + 2;
cur_v += 2;
cur = cur / 2;
}
}
}
cout << 100 << endl;
for (int i = 1; i <= 100; ++i)
{
cout << edge[i][0] << " " << edge[i][1] << endl;
}
}
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 | #include <bits/stdc++.h> using namespace std; int edge[101][2]; int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); for (int i = 1; i <= 100; ++i) { edge[i][0] = edge[i][1] = -1; } long long k; cin >> k; // wierzchołki 1, 2 i 3 edge[99][0] = 100; edge[98][0] = 100; edge[98][1] = 99; long long cur = k; int cur_v = 1; while(true){ if(cur == 1){ edge[cur_v][0] = 100; break; } if(cur == 2){ edge[cur_v][0] = 98; break; } if(cur == 3){ edge[cur_v][1] = 99; edge[cur_v][0] = 98; break; } if(cur >= 4){ if(cur % 2 == 0){ edge[cur_v][0] = cur_v + 1; edge[cur_v][1] = cur_v + 2; edge[cur_v + 1][0] = 98; edge[cur_v + 1][1] = cur_v + 2; cur_v += 2; cur = cur / 2 - 1; } else{ edge[cur_v][0] = cur_v + 1; edge[cur_v][1] = cur_v + 2; edge[cur_v + 1][0] = 99; edge[cur_v + 1][1] = cur_v + 2; cur_v += 2; cur = cur / 2; } } } cout << 100 << endl; for (int i = 1; i <= 100; ++i) { cout << edge[i][0] << " " << edge[i][1] << endl; } } |
English