Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define all(x) begin(x), end(x)
- #define sz(x) static_cast<int>((x).size())
- #define int long long
- signed main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n, s;
- cin >> n >> s;
- if (s & 1 || n > s || n == 1) {
- cout << -1 << "\n";
- continue;
- }
- int dp[30] = {0};
- for (int i = 0; i < 30; i++) {
- if (s & (1ll << i)) dp[i]++;
- }
- for (int i = 29; i > 0; i--) {
- if (dp[i] & 1) dp[i - 1] += 2, dp[i]--;
- int ex = (n - dp[i - 1]) / 2;
- if (ex & 1) ex--;
- dp[i - 1] += min(ex, dp[i]) * 2;
- dp[i] -= min(ex, dp[i]);
- }
- int a[n] = {0};
- int i = 0;
- int cur = 1;
- for (auto u : dp) {
- for (int j = 0; j < u; j++, i++) {
- if (i == n) i = 0;
- a[i] += cur;
- }
- cur *= 2;
- }
- bool ps = 1;
- for (auto u : a) {
- if (u == 0) ps = 0;
- }
- if (!ps) {
- cout << -1 << "\n";
- continue;
- }
- for (auto u : a) cout << u << " ";
- cout << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement