#include<bits/stdc++.h> using namespace std; using pii = pair<int, int>; using pll = pair<long long, long long>; using pil = pair<int, long long>; using pli = pair<long long, int>; using ll = long long; #define X first #define Y second #define pb push_back #define mp make_pair int k,p; int t[]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>k; if(k==1){ cout << "2\n2 -1\n-1 -1"; return 0; } while(t[p]<=k){ p++; } p--; cout << 2*p+2 << "\n"; for(int i = 1; i<=2*p+2; i++){ //cout << i << ": "; if(i<2*p+2) cout << i+1 << " "; else cout << -1 << " "; if(i%2 && i<=2*p) cout << i+2 << "\n"; else if(!(i%2) && t[i/2-1]&k && i<=2*p) cout << 2*p+2 << "\n"; else cout << -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 | #include<bits/stdc++.h> using namespace std; using pii = pair<int, int>; using pll = pair<long long, long long>; using pil = pair<int, long long>; using pli = pair<long long, int>; using ll = long long; #define X first #define Y second #define pb push_back #define mp make_pair int k,p; int t[]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>k; if(k==1){ cout << "2\n2 -1\n-1 -1"; return 0; } while(t[p]<=k){ p++; } p--; cout << 2*p+2 << "\n"; for(int i = 1; i<=2*p+2; i++){ //cout << i << ": "; if(i<2*p+2) cout << i+1 << " "; else cout << -1 << " "; if(i%2 && i<=2*p) cout << i+2 << "\n"; else if(!(i%2) && t[i/2-1]&k && i<=2*p) cout << 2*p+2 << "\n"; else cout << -1 << "\n"; } return 0; } |