题目
思路
从后往前推,每次取当前灵石数的一半即可。
代码
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
using namespace std;
#define _CRT_SECURE_NO_WARNINGS 1
#define ll long long
#define pub push_back
#define pob pop_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define inf 2e9
#define llf 1e19
#define endl "\n"
const ll mod = 1e9 + 7;
ll qpow(ll base, ll power)
{
ll res = 1;
while (power > 0)
{
if (power & 1) res = base * res % mod;
power >>= 1;
base = base * base % mod;
}
return res;
}
ll gcd(ll a, ll b)
{
return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
return a / gcd(a, b) * b;
}
double dis(double x, double y, double x1, double y1)
{
return sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
}
double dis1(double x, double y, double z, double x1, double y1, double z1)
{
return sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1) + (z - z1) * (z - z1));
}
double chaji(double x1, double x2, double y1, double y2)
{
return x1 * y2 - x2 * y1;
}
ll n, m;
ll ans[100010];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
ll i, nn;
cin >> n >> m;
nn = n;
while (nn > 1)
{
if (m % 2 == 0) ans[nn] = m / 2;
else ans[nn] = m / 2 + 1;
m = m / 2;
nn--;
if (m < 1)
{
cout << -1;
return 0;
}
}
ans[1] = m;
for (i = 1; i <= n; i++) cout << ans[i] << ' ';
}