#include <cstdio>
#include <algorithm>
#define MAKS 1000010
#define NAJ 1000000000000000000LL
using namespace std;
typedef long long int lld;
lld f(int n)
{
if(n>=60)return NAJ;
return (1LL << lld(n)) - 1LL;
}
int main()
{
int n; lld k;
scanf("%d %lld",&n,&k);
if(f(n)*3LL<k)
{
puts("NIE");
return 0;
}
k++;
int poprz=-1;
for(int i=n;i>=1;i--)
{
if(k==1)break;
k--;
for(int j=0;j<3;j++)
{
if(j==poprz)continue;
if(k<=f(i))
{
printf("%c",'a'+j);
poprz=j;
break;
}
k-=f(i);
}
}
puts("");
}
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 | #include <cstdio> #include <algorithm> #define MAKS 1000010 #define NAJ 1000000000000000000LL using namespace std; typedef long long int lld; lld f(int n) { if(n>=60)return NAJ; return (1LL << lld(n)) - 1LL; } int main() { int n; lld k; scanf("%d %lld",&n,&k); if(f(n)*3LL<k) { puts("NIE"); return 0; } k++; int poprz=-1; for(int i=n;i>=1;i--) { if(k==1)break; k--; for(int j=0;j<3;j++) { if(j==poprz)continue; if(k<=f(i)) { printf("%c",'a'+j); poprz=j; break; } k-=f(i); } } puts(""); } |
English