#include <iostream> #include <stdio.h> using namespace std; int invert(int power, int n) { return power == -1 ? power : n + 1 - power; } int main() { int k; cin >> k; int graph[101][2]; int power[101]; graph[1][0] = -1; graph[1][1] = -1; graph[2][0] = 1; graph[2][1] = -1; power[1] = 1; power[2] = 1; int max = 2; int n = 2; while (max < k) { n++; graph[n][0] = n - 1; graph[n][1] = n - 2; power[n] = power[n - 1] + power[n - 2]; max += power[n]; } int range = n - 1; int currentPower = power[n]; while (currentPower < k) { n++; graph[n][0] = n - 1; while (currentPower + power[range] > k) { range--; } currentPower += power[range]; graph[n][1] = range; } printf("%d\n", n); for (int i = n; i >= 1; i--) { printf("%d %d\n", invert(graph[i][0], n), invert(graph[i][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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include <iostream> #include <stdio.h> using namespace std; int invert(int power, int n) { return power == -1 ? power : n + 1 - power; } int main() { int k; cin >> k; int graph[101][2]; int power[101]; graph[1][0] = -1; graph[1][1] = -1; graph[2][0] = 1; graph[2][1] = -1; power[1] = 1; power[2] = 1; int max = 2; int n = 2; while (max < k) { n++; graph[n][0] = n - 1; graph[n][1] = n - 2; power[n] = power[n - 1] + power[n - 2]; max += power[n]; } int range = n - 1; int currentPower = power[n]; while (currentPower < k) { n++; graph[n][0] = n - 1; while (currentPower + power[range] > k) { range--; } currentPower += power[range]; graph[n][1] = range; } printf("%d\n", n); for (int i = n; i >= 1; i--) { printf("%d %d\n", invert(graph[i][0], n), invert(graph[i][1], n)); } return 0; } |