#include <iostream> #include <vector> #include <algorithm> int main() { int k; std::cin >> k; std::vector<int> bin; while (k != 0) { bin.push_back(k % 2); k /= 2; } while (bin.size() < 30) { bin.push_back(0); } std::reverse(bin.begin(), bin.end()); std::cout << "89\n"; for (int i = 1; i <= 30; i++) { if (i < 30) { if (bin[i - 1] == 1) { std::cout << i + 1 << " " << 30 + 2 * i - 1 << "\n"; } else { std::cout << i + 1 << " " << -1 << "\n"; } } else { if (bin[i - 1] == 1) { std::cout << -1 << " " << 30 + 2 * i - 1 << "\n"; } else { std::cout << -1 << " " << -1 << "\n"; } } } for (int i = 31; i < 89; i++) { if (i % 2 == 1) { std::cout << i + 1 << " " << i + 2 << "\n"; } else { std::cout << i + 1 << " " << -1 << "\n"; } } std::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 34 35 36 37 38 39 40 41 42 43 | #include <iostream> #include <vector> #include <algorithm> int main() { int k; std::cin >> k; std::vector<int> bin; while (k != 0) { bin.push_back(k % 2); k /= 2; } while (bin.size() < 30) { bin.push_back(0); } std::reverse(bin.begin(), bin.end()); std::cout << "89\n"; for (int i = 1; i <= 30; i++) { if (i < 30) { if (bin[i - 1] == 1) { std::cout << i + 1 << " " << 30 + 2 * i - 1 << "\n"; } else { std::cout << i + 1 << " " << -1 << "\n"; } } else { if (bin[i - 1] == 1) { std::cout << -1 << " " << 30 + 2 * i - 1 << "\n"; } else { std::cout << -1 << " " << -1 << "\n"; } } } for (int i = 31; i < 89; i++) { if (i % 2 == 1) { std::cout << i + 1 << " " << i + 2 << "\n"; } else { std::cout << i + 1 << " " << -1 << "\n"; } } std::cout << "-1 -1"; return 0; } |