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
| #include <iostream> #include <cstdio> #include <algorithm> #include <cstdlib> #include <cstring> #include <ctype.h> using namespace std; typedef unsigned long long ull;
inline ull read() { ull x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 48; ch = getchar(); } return x * f; }
const int maxn = 64;
ull n, k;
void dfs(ull n, ull k, ull rev, ull from) { if (n == 1) { if (rev == 0) { if (k == 0) printf("0"); else printf("1"); } else { if (k == 0) printf("1"); else printf("0"); } return; } if (k <= (1LL << (n - 1LL)) - 1LL) { if (rev == 0 && from == 0) { printf("0"); dfs(n - 1LL, k, 0LL, 0LL); } else if (rev == 0 && from == 1) { printf("0"); dfs(n - 1LL, k, 1LL, 0LL); } else if (rev == 1 && from == 0) { printf("1"); dfs(n - 1LL, k, 0LL, 0LL); } else { printf("1"); dfs(n - 1LL, k, 0LL, 0LL); } } else { if (rev == 0 && from == 0) { printf("1"); dfs(n - 1LL, k - (1LL << (n - 1LL)), 1LL, 1LL); } else if (rev == 1 && from == 0) { printf("0"); dfs(n - 1LL, k - (1LL << (n - 1LL)), 0LL, 1LL); } else if (rev == 0 && from == 1) { printf("1"); dfs(n - 1LL, k - (1LL << (n - 1LL)), 0LL, 1LL); } else { printf("0"); dfs(n - 1LL, k - (1LL << (n - 1LL)), 1LL, 1LL); } } }
int main() { n = read(); k = read(); dfs(n, k, 0, 0); printf("\n"); return 0; }
|