#include <bits/stdc++.h> #define gc getchar #define gcu getchar_unlocked #define fi first #define se second #define pb push_back #define mod ((ll)1e9 + 7) typedef long long ll; using namespace std; //=============================================================================================== int m; ll n; ll a[10009]; pair<int, int> ans[10009]; //=============================================================================================== int main() { scanf("%lld", &n); if (n == 1) { printf("2\n2 -1\n-1 -1\n"); return 0; } if (n == 2) { printf("3\n2 3\n3 -1\n-1 -1\n"); return 0; } a[1] = 1; for (int i = 1; i <= 100; i++) { if (a[i] >= n) { n -= a[i - 1]; m = i - 1; break; } ans[i].fi = i + 1; a[i + 1] += a[i]; if (i % 2) { ans[i].se = i + 3; a[i + 3] += a[i]; } // printf("%3d %3d %3d %lld\n", i, ans[i].fi, ans[i].se, a[i]); } printf("%d\n", m); for (int i = m - 1; i; i--) { // printf(" %lld %lld\n", a[i], n); if (a[i] <= n && !ans[i].se) { n -= a[i]; ans[i].se = m; } } for (int i = 1; i <= m; i++) { if (!ans[i].fi || ans[i].fi > m) ans[i].fi = -1; if (!ans[i].se || ans[i].se > m) ans[i].se = -1; printf("%d %d\n", ans[i].fi, ans[i].se); } } //===============================================================================================
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | #include <bits/stdc++.h> #define gc getchar #define gcu getchar_unlocked #define fi first #define se second #define pb push_back #define mod ((ll)1e9 + 7) typedef long long ll; using namespace std; //=============================================================================================== int m; ll n; ll a[10009]; pair<int, int> ans[10009]; //=============================================================================================== int main() { scanf("%lld", &n); if (n == 1) { printf("2\n2 -1\n-1 -1\n"); return 0; } if (n == 2) { printf("3\n2 3\n3 -1\n-1 -1\n"); return 0; } a[1] = 1; for (int i = 1; i <= 100; i++) { if (a[i] >= n) { n -= a[i - 1]; m = i - 1; break; } ans[i].fi = i + 1; a[i + 1] += a[i]; if (i % 2) { ans[i].se = i + 3; a[i + 3] += a[i]; } // printf("%3d %3d %3d %lld\n", i, ans[i].fi, ans[i].se, a[i]); } printf("%d\n", m); for (int i = m - 1; i; i--) { // printf(" %lld %lld\n", a[i], n); if (a[i] <= n && !ans[i].se) { n -= a[i]; ans[i].se = m; } } for (int i = 1; i <= m; i++) { if (!ans[i].fi || ans[i].fi > m) ans[i].fi = -1; if (!ans[i].se || ans[i].se > m) ans[i].se = -1; printf("%d %d\n", ans[i].fi, ans[i].se); } } //=============================================================================================== |