#include <bits/stdc++.h> using namespace std; int k; vector<int> v[107]; int main() { ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> k; int pp = 1, a=2, b=3; for (int l=1; l<=k; l*=2) { v[pp].push_back(a); v[pp].push_back(b); if ((k&l)>0){ v[a].push_back(100); } v[a].push_back(b+1); v[b].push_back(b+1); pp+=3; a+=3; b+=3; } cout<<b-1<<"\n"; for (int i=1; i<=b-1; i++){ if (v[i].size()==2 ) cout<<min(v[i][1], b-1)<<" "<<min(v[i][0], b-1)<<"\n"; else if (v[i].empty()) cout<<-1<<" "<<-1<<"\n"; else cout<<min(v[i][0], b-1)<<" -1\n"; } }
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 | #include <bits/stdc++.h> using namespace std; int k; vector<int> v[107]; int main() { ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> k; int pp = 1, a=2, b=3; for (int l=1; l<=k; l*=2) { v[pp].push_back(a); v[pp].push_back(b); if ((k&l)>0){ v[a].push_back(100); } v[a].push_back(b+1); v[b].push_back(b+1); pp+=3; a+=3; b+=3; } cout<<b-1<<"\n"; for (int i=1; i<=b-1; i++){ if (v[i].size()==2 ) cout<<min(v[i][1], b-1)<<" "<<min(v[i][0], b-1)<<"\n"; else if (v[i].empty()) cout<<-1<<" "<<-1<<"\n"; else cout<<min(v[i][0], b-1)<<" -1\n"; } } |