#include <cstdio> #include <cstdlib> int main() { int n; scanf("%d", &n); int length = 0; int flipped_n = 0; while (n > 0) { flipped_n <<= 1; flipped_n |= n & 1; n >>= 1; length++; } printf("%d\n", 3 * length + 4); for (int i = 0; i < length; i++) { const int next_path = 3 * i + 4; const int next_braid1 = 3 * i + 5; const int next_braid2 = 3 * i + 6; printf("%d %d\n", next_path, (flipped_n & 1) ? next_braid1 : -1); printf("%d %d\n", next_braid1, next_braid2); printf("%d %d\n", next_braid1, next_braid2); flipped_n >>= 1; } puts("-1 -1"); printf("%d %d\n", 3 * length + 4, -1); printf("%d %d\n", 3 * length + 4, -1); puts("-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 | #include <cstdio> #include <cstdlib> int main() { int n; scanf("%d", &n); int length = 0; int flipped_n = 0; while (n > 0) { flipped_n <<= 1; flipped_n |= n & 1; n >>= 1; length++; } printf("%d\n", 3 * length + 4); for (int i = 0; i < length; i++) { const int next_path = 3 * i + 4; const int next_braid1 = 3 * i + 5; const int next_braid2 = 3 * i + 6; printf("%d %d\n", next_path, (flipped_n & 1) ? next_braid1 : -1); printf("%d %d\n", next_braid1, next_braid2); printf("%d %d\n", next_braid1, next_braid2); flipped_n >>= 1; } puts("-1 -1"); printf("%d %d\n", 3 * length + 4, -1); printf("%d %d\n", 3 * length + 4, -1); puts("-1 -1"); return 0; } |