#include <bits/stdc++.h> typedef long long ll; using namespace std; struct node{ ll dp; int x1, x2; }; ll k; node tab[105]; int main() { scanf("%lld", &k); tab[1].x1 = -1; tab[1].x2 = -1; tab[1].dp = 1; tab[2].x1 = -1; tab[2].x2 = 1; tab[2].dp = 1; for(int i = 3; i<=44; i++) { tab[i].x1 = i-1; tab[i].x2 = i-2; tab[i].dp = tab[i-1].dp + tab[i-2].dp; } for(int i = 45; i<=100; i++) { tab[i].x1 = -1; tab[i].x2 = -1; tab[i].dp = 0; } int it = 45; int curfib = 44; for(int i = 1; i<=1; i++) { while(tab[curfib].dp > k) curfib--; tab[it].x1 = curfib; k-=tab[curfib].dp; curfib--; if(k == 0) { it++; break; } while(tab[curfib].dp > k) curfib--; tab[it].x2 = curfib; k-=tab[curfib].dp; it++; } while(k!=0){ tab[it].x1 = it-1; while(tab[curfib].dp > k) curfib--; tab[it].x2 = curfib; k-=tab[curfib].dp; it++; } printf("%d\n", it-1); int a, b; for(int i = it-1; i>=1; i--) { if(tab[i].x1 == -1) { a = -1; } else { a = it-tab[i].x1; } if(tab[i].x2 == -1) { b = -1; } else { b = it-tab[i].x2; } printf("%d %d\n", a, b); } }
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 69 70 71 72 73 74 75 76 77 78 79 80 81 | #include <bits/stdc++.h> typedef long long ll; using namespace std; struct node{ ll dp; int x1, x2; }; ll k; node tab[105]; int main() { scanf("%lld", &k); tab[1].x1 = -1; tab[1].x2 = -1; tab[1].dp = 1; tab[2].x1 = -1; tab[2].x2 = 1; tab[2].dp = 1; for(int i = 3; i<=44; i++) { tab[i].x1 = i-1; tab[i].x2 = i-2; tab[i].dp = tab[i-1].dp + tab[i-2].dp; } for(int i = 45; i<=100; i++) { tab[i].x1 = -1; tab[i].x2 = -1; tab[i].dp = 0; } int it = 45; int curfib = 44; for(int i = 1; i<=1; i++) { while(tab[curfib].dp > k) curfib--; tab[it].x1 = curfib; k-=tab[curfib].dp; curfib--; if(k == 0) { it++; break; } while(tab[curfib].dp > k) curfib--; tab[it].x2 = curfib; k-=tab[curfib].dp; it++; } while(k!=0){ tab[it].x1 = it-1; while(tab[curfib].dp > k) curfib--; tab[it].x2 = curfib; k-=tab[curfib].dp; it++; } printf("%d\n", it-1); int a, b; for(int i = it-1; i>=1; i--) { if(tab[i].x1 == -1) { a = -1; } else { a = it-tab[i].x1; } if(tab[i].x2 == -1) { b = -1; } else { b = it-tab[i].x2; } printf("%d %d\n", a, b); } } |