题目传送门P5657
评测记录
代码:
#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;
int n; ull k;
string s = "";
void Gray(ull x, int N) {
if (N == 1) {
s += (x == 0) ? '0' : '1';
return;
}
if (x >= pow(2, N - 1)) {
s += '1'; Gray(pow(2, N) - x - 1, N - 1);
} else {
s += '0'; Gray(x, N - 1);
}
}
int main(void) {
cin >> n >> k;
Gray(k, n);
cout << s << '\n';
return 0;
}