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
| #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef pair<int, int> pii; typedef pair<string, string> pss;
#define rep(i, a, n) for (int i = a; i < n; ++i) #define per(i, a, n) for (int i = n - 1; i >= a; --i) #define fi first #define se second #define pb push_back #define np next_permutation #define mp make_pair #define endl '\n' #define INF 0x3f3f3f3f
const int maxn = 1e5 + 5; ll a[maxn], presum[maxn];
void init() { a[0] = presum[0] = 1; rep(i, 1, 33) { a[i] = a[i - 1] * 2; presum[i] = presum[i - 1] + a[i]; } }
ll n, t; vi ans;
void solve(ll start, ll len, ll cnt) { int index = lower_bound(presum, presum + len, cnt) - presum; if (cnt == presum[index - 1]) { ans.pb(start + len - index + 1); return; } if (index == len) { return; } ans.pb(start + len - index); solve(start + len - index, index, cnt - presum[index - 1]); }
int main() { init(); while (cin >> n >> t) { ans.clear(); ll temp = 2; rep(i, 1, n) temp *= 2; solve(0, n, temp + 1 - t); if (!ans.size()) { cout << "0" << endl; continue; } cout << ans[0]; rep(i, 1, ans.size()) { cout << " " << ans[i]; } cout << endl; } }
|