#include <bits/stdc++.h> #define st first #define nd second #define pb push_back #define BOOST ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); #define PI 3.14159265359 using namespace std; typedef long long ll; constexpr ll MOD = 1000000007, hot = 29; constexpr ll FOX = 1234567891, cute = 1009; constexpr ll MEGAN = 1000000009, liv = 107; constexpr int MXN = 1000000+7 + 10, CZAPA = (1<<20), INF = 1000000000; int edges[107][2]; int main(){ BOOST; int k; cin>> k; if(k == 1){ cout<< "2\n2 -1\n-1 -1\n"; return 0; } int idx = 1; while((1<<idx) <= k) idx++; idx--; int n = 2 * (idx+1); for(int i=1; i<=n-2; i++){ if(i % 2 == 0){ edges[i][0] = i+1; } else{ edges[i][0] = i+1; edges[i][1] = i+2; } } edges[n-1][0] = n; for(int i=0; i<idx; i++){ if(((1<<i)&(k)) > 0){ edges[2*(i+1)][1] = n; } } cout<< n << '\n'; for(int i=1; i<=n; i++){ if(edges[i][0] == 0) edges[i][0] = -1; if(edges[i][1] == 0) edges[i][1] = -1; cout<< edges[i][0] << ' ' << edges[i][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 46 47 48 49 50 51 52 53 54 55 56 | #include <bits/stdc++.h> #define st first #define nd second #define pb push_back #define BOOST ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); #define PI 3.14159265359 using namespace std; typedef long long ll; constexpr ll MOD = 1000000007, hot = 29; constexpr ll FOX = 1234567891, cute = 1009; constexpr ll MEGAN = 1000000009, liv = 107; constexpr int MXN = 1000000+7 + 10, CZAPA = (1<<20), INF = 1000000000; int edges[107][2]; int main(){ BOOST; int k; cin>> k; if(k == 1){ cout<< "2\n2 -1\n-1 -1\n"; return 0; } int idx = 1; while((1<<idx) <= k) idx++; idx--; int n = 2 * (idx+1); for(int i=1; i<=n-2; i++){ if(i % 2 == 0){ edges[i][0] = i+1; } else{ edges[i][0] = i+1; edges[i][1] = i+2; } } edges[n-1][0] = n; for(int i=0; i<idx; i++){ if(((1<<i)&(k)) > 0){ edges[2*(i+1)][1] = n; } } cout<< n << '\n'; for(int i=1; i<=n; i++){ if(edges[i][0] == 0) edges[i][0] = -1; if(edges[i][1] == 0) edges[i][1] = -1; cout<< edges[i][0] << ' ' << edges[i][1] << '\n'; } return 0; } |