很简单!不就是将 二进制的结果存起来。遍历 至 ,是 ,就输出 ;遍历 至 ,是 ,就输出 ;
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef void vd;
typedef bool bl;
inline ll read() {
ll s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
inline vd print(ll x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x >= 10)
print(x / 10);
putchar(x % 10 + '0');
return;
}
ll n,m,k,a[55];
int main() {
n=read(),m=read()-1;
while(m) {
a[++k]=m%2;
m>>=1;
}
for(ll i=1;i<=n;i++)
if(!a[n-i]) print(i),printf(" ");
for(ll i=n;i>=1;i--)
if(a[n-i]) print(i),printf(" ");
return 0;
}