#include <bits/stdc++.h> #define fi first #define sc second #define forn(i,p,k) for(int i=(p);i<=(k);++i) #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int,int> pii; int L[101],R[101]; int akt=99; void solve(const int &x) { if(x==1) return; solve(x>>1); L[akt]=akt+1; akt--; L[akt]=akt+1; R[akt]=akt+2; akt--; if(x&1) { L[akt]=akt+1; R[akt]=100; akt--; } } int main() { ios_base::sync_with_stdio(0); int k; cin>>k; solve(k); L[1]=akt+1; cout<<100<<"\n"; forn(i,1,100) cout<<(L[i]==0?-1:L[i])<<" "<<(R[i]==0?-1:R[i])<<"\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 | #include <bits/stdc++.h> #define fi first #define sc second #define forn(i,p,k) for(int i=(p);i<=(k);++i) #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int,int> pii; int L[101],R[101]; int akt=99; void solve(const int &x) { if(x==1) return; solve(x>>1); L[akt]=akt+1; akt--; L[akt]=akt+1; R[akt]=akt+2; akt--; if(x&1) { L[akt]=akt+1; R[akt]=100; akt--; } } int main() { ios_base::sync_with_stdio(0); int k; cin>>k; solve(k); L[1]=akt+1; cout<<100<<"\n"; forn(i,1,100) cout<<(L[i]==0?-1:L[i])<<" "<<(R[i]==0?-1:R[i])<<"\n"; return 0; } |