递归,当k超过总位数一半时输出1,否则输出0
#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
void fun(ull n,ull k){
if(n==1){
if(k==1){
cout<<0;
}else{
cout<<1;
}
return;
}
ull k2=pow(2,n-1);
if(k<=k2){
cout<<0;
fun(n-1,k);
}else{
cout<<1;
ull k3=k2*2;
fun(n-1,k3-k+1);
}
}
int main(){
ull n,k;
cin>>n>>k;
fun(n,k+1);
return 0;
}