#include <bits/stdc++.h> #define ll long long using namespace std; int k, dod[100]; int main() { cin>>k; vector<int> sum; int i=29, pot=1<<29; while(k){ if(k>=pot){ k-=pot; sum.push_back(i); } i--; pot/=2; } // for(int j: sum) cout<<j<<' '; // cout<<endl; int n=2*sum[0]+2; cout<<n<<'\n'; for(int j=1; j<sum.size(); ++j){ dod[2*sum[j]+2]=n; } for(int i=1; i<n; ++i){ cout<<i+1<<' '; if(i%2==1&&i+2<=n) cout<<i+2<<'\n'; else if(i%2==0&&dod[i])cout<<dod[i]<<'\n'; else cout<<-1<<'\n'; } cout<<-1<<' '<<-1; 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 | #include <bits/stdc++.h> #define ll long long using namespace std; int k, dod[100]; int main() { cin>>k; vector<int> sum; int i=29, pot=1<<29; while(k){ if(k>=pot){ k-=pot; sum.push_back(i); } i--; pot/=2; } // for(int j: sum) cout<<j<<' '; // cout<<endl; int n=2*sum[0]+2; cout<<n<<'\n'; for(int j=1; j<sum.size(); ++j){ dod[2*sum[j]+2]=n; } for(int i=1; i<n; ++i){ cout<<i+1<<' '; if(i%2==1&&i+2<=n) cout<<i+2<<'\n'; else if(i%2==0&&dod[i])cout<<dod[i]<<'\n'; else cout<<-1<<'\n'; } cout<<-1<<' '<<-1; return 0; } |