#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int k; cin >> k; int bubbles = 31 - __builtin_clz(k); int sticks = __builtin_popcount(k) - 1; int total = (bubbles + 1) * 2 + sticks; if(k == 1){ cout << "2\n2 -1\n-1 -1\n"; return 0; } cout << total << "\n"; // cout << bubbles << " " << sticks << "\n"; int it = 2; for(int i = 0; i < bubbles; i++){ if(k & (1 << i)){ cout << it++ << " " << total - 2 * (i + 1) << "\n"; } } it--; cout << it + 1 << " " << it + 2 << "\n"; // łączoncy dodatkowe z resztą it = it + 2; for(int i = 0; i < bubbles - 1; i++){ cout << it + 1 << " " << it + 2 << "\n" << it + 1 << " " << it + 2 << "\n"; it = it + 2; } cout << total << " " << "-1\n" << total << " " << "-1\n" << "-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 | #include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int k; cin >> k; int bubbles = 31 - __builtin_clz(k); int sticks = __builtin_popcount(k) - 1; int total = (bubbles + 1) * 2 + sticks; if(k == 1){ cout << "2\n2 -1\n-1 -1\n"; return 0; } cout << total << "\n"; // cout << bubbles << " " << sticks << "\n"; int it = 2; for(int i = 0; i < bubbles; i++){ if(k & (1 << i)){ cout << it++ << " " << total - 2 * (i + 1) << "\n"; } } it--; cout << it + 1 << " " << it + 2 << "\n"; // łączoncy dodatkowe z resztą it = it + 2; for(int i = 0; i < bubbles - 1; i++){ cout << it + 1 << " " << it + 2 << "\n" << it + 1 << " " << it + 2 << "\n"; it = it + 2; } cout << total << " " << "-1\n" << total << " " << "-1\n" << "-1 -1\n"; } |