#include<bits/stdc++.h> using namespace std; long long l[107], r[107], k, maksD = 1ll << 32; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); fill(l, l + 107, -1); fill(r, r + 107, -1); cin >> k; for(long long i = 1;i < 16;i++){ l[i] = i * 2; r[i] = i * 2 + 1; } for(long long i = 99, j = 0;i >= 31;i--){ l[i] = i + 1; if(i % 2 == 0){ if((1ll << ++j) <= k) r[i] = i + 2; } } while(maksD > k) maksD /= 2; for(long long i = 30, curr = k - maksD;i >= 0;i--){ if((1ll << i) <= curr){ curr -= (1ll << i); long long j = i / 2; if(i % 2 == 0) l[j + 16] = 100 - 2 * i; if(i % 2 == 1) r[j + 16] = 100 - 2 * i; } } cout << 100 << '\n'; for(long long i = 1;i <= 100;i++) cout << l[i] << ' ' << r[i] << '\n'; }
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 | #include<bits/stdc++.h> using namespace std; long long l[107], r[107], k, maksD = 1ll << 32; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); fill(l, l + 107, -1); fill(r, r + 107, -1); cin >> k; for(long long i = 1;i < 16;i++){ l[i] = i * 2; r[i] = i * 2 + 1; } for(long long i = 99, j = 0;i >= 31;i--){ l[i] = i + 1; if(i % 2 == 0){ if((1ll << ++j) <= k) r[i] = i + 2; } } while(maksD > k) maksD /= 2; for(long long i = 30, curr = k - maksD;i >= 0;i--){ if((1ll << i) <= curr){ curr -= (1ll << i); long long j = i / 2; if(i % 2 == 0) l[j + 16] = 100 - 2 * i; if(i % 2 == 1) r[j + 16] = 100 - 2 * i; } } cout << 100 << '\n'; for(long long i = 1;i <= 100;i++) cout << l[i] << ' ' << r[i] << '\n'; } |