//Mateusz Pabian Jagiellonian University
#include <iostream>
#include <string>
#include <queue>
using namespace std;
queue <char> res;
int main()
{
long long n,k;
long long d,last;
bool f=true;
ios_base::sync_with_stdio(0);
cin >>n>>k;
if(n<60)
{
if( ((1<<n)-1)*3 < k ) f=false;
}
if (f)
{
if (n>60) n=60;
//cout<<"x: "<<n<<endl;
d=((1L<<n)-1L);
//cout<<"x: "<<d<<endl;
if(k<=d) { res.push('a'); last=1; }
else if(k<=d*2) { res.push('b'); last=2; k-=d;}
else { res.push('c'); last=3; k-=2*d;}
int o=20;
while(k)
{
//cout<<"K: "<<k<<endl;
//cout<<"D: "<<d<<endl;
if(k==1) break;
d--;
d/=2;
k--;
if(last==1)
{
if(k<=d) {res.push('b'); last=2;}
else {res.push('c'); last=3; k-=d;}
}
else if(last==2)
{
if(k<=d) {res.push('a'); last=1;}
else {res.push('c'); last=3; k-=d;}
}
else
{
if(k<=d) {res.push('a'); last=1;}
else {res.push('b'); last=2; k-=d;}
}
//cout<<res.front()<<endl;
}
while(res.empty()==false)
{
cout<<res.front();
res.pop();
}
cout<<endl;
}
else
{
cout<<"NIE"<<endl;
}
}
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 | //Mateusz Pabian Jagiellonian University #include <iostream> #include <string> #include <queue> using namespace std; queue <char> res; int main() { long long n,k; long long d,last; bool f=true; ios_base::sync_with_stdio(0); cin >>n>>k; if(n<60) { if( ((1<<n)-1)*3 < k ) f=false; } if (f) { if (n>60) n=60; //cout<<"x: "<<n<<endl; d=((1L<<n)-1L); //cout<<"x: "<<d<<endl; if(k<=d) { res.push('a'); last=1; } else if(k<=d*2) { res.push('b'); last=2; k-=d;} else { res.push('c'); last=3; k-=2*d;} int o=20; while(k) { //cout<<"K: "<<k<<endl; //cout<<"D: "<<d<<endl; if(k==1) break; d--; d/=2; k--; if(last==1) { if(k<=d) {res.push('b'); last=2;} else {res.push('c'); last=3; k-=d;} } else if(last==2) { if(k<=d) {res.push('a'); last=1;} else {res.push('c'); last=3; k-=d;} } else { if(k<=d) {res.push('a'); last=1;} else {res.push('b'); last=2; k-=d;} } //cout<<res.front()<<endl; } while(res.empty()==false) { cout<<res.front(); res.pop(); } cout<<endl; } else { cout<<"NIE"<<endl; } } |
English