#include <iostream> using namespace std; int main(){ int64_t k; cin >> k; if (k==1){ cout<<"2\n 2 -1\n -1 -1"<<endl; return 0; } int lev = 0; auto kk=k; while (kk>1){ kk/=2; lev++; } int n= lev*2+2; cout<<n<<endl; for (int i = 1; i<=lev; i++ ){ int t = (k%2==1)?n:-1; k=k/2; cout<< 2*i <<" "<< 2*i +1<< endl; cout<< 2*i+1 <<" "<< t << endl; } cout<<n<<" -1"<<endl; cout<<"-1 -1"<<endl; 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 | #include <iostream> using namespace std; int main(){ int64_t k; cin >> k; if (k==1){ cout<<"2\n 2 -1\n -1 -1"<<endl; return 0; } int lev = 0; auto kk=k; while (kk>1){ kk/=2; lev++; } int n= lev*2+2; cout<<n<<endl; for (int i = 1; i<=lev; i++ ){ int t = (k%2==1)?n:-1; k=k/2; cout<< 2*i <<" "<< 2*i +1<< endl; cout<< 2*i+1 <<" "<< t << endl; } cout<<n<<" -1"<<endl; cout<<"-1 -1"<<endl; return 0; } |