#include<bits/stdc++.h> #define fi first #define se second using namespace std; int n=1; vector<pair<int,int>> ans; void f(int k) { if(k==1) ans.push_back({-1,-1}); else if(k%2==1) { ans.push_back({n+1,-2}); n++; f(k-1); } else { ans.push_back({n+1,n+2}); ans.push_back({n+2,-1}); n+=2; f(k/2); } return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int k; cin>>k; if(k==1) { cout<<"2\n"<<"2 -1\n"<<"-1 -1\n"; return 0; } f(k); cout<<n<<"\n"; for(auto v:ans) { cout<<(v.fi==-2 ? n:v.fi)<<" "<<(v.se==-2 ? n:v.se)<<"\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<bits/stdc++.h> #define fi first #define se second using namespace std; int n=1; vector<pair<int,int>> ans; void f(int k) { if(k==1) ans.push_back({-1,-1}); else if(k%2==1) { ans.push_back({n+1,-2}); n++; f(k-1); } else { ans.push_back({n+1,n+2}); ans.push_back({n+2,-1}); n+=2; f(k/2); } return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int k; cin>>k; if(k==1) { cout<<"2\n"<<"2 -1\n"<<"-1 -1\n"; return 0; } f(k); cout<<n<<"\n"; for(auto v:ans) { cout<<(v.fi==-2 ? n:v.fi)<<" "<<(v.se==-2 ? n:v.se)<<"\n"; } return 0; } |