#include <iostream>
#include <climits>
using namespace std;
unsigned long long pow(unsigned long long p, unsigned long long w)
{
unsigned long long r = 1;
while (w--)
{
if (ULLONG_MAX/p<=r)
return ULLONG_MAX;
r*=p;
}
return r;
}
int main() {
// your code goes here
unsigned long long n,k;
char pop;
scanf("%llu%llu",&n,&k);
if(n<=62)
{
if(k>3ULL*(pow(2ULL,n)-1ULL)) {printf("NIE\n");return 0;}
}
if (k<=pow(2ULL,n)-1) pop='a';
else if (k>2*pow(2ULL,n)-1) pop='c';
else pop='b';
printf("%c",pop);
while(k!=1ULL)
{
if(k<=pow(2ULL,n-1ULL)-1)
{
if(pop=='a') pop = 'b';
else pop = 'a';
}
else
{
if(pop=='c') pop = 'b';
else pop = 'c';
k-=pow(2ULL,n-1ULL);
}
printf("%c",pop);
n--;
}
printf("\n");
return 0;
}
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 | #include <iostream> #include <climits> using namespace std; unsigned long long pow(unsigned long long p, unsigned long long w) { unsigned long long r = 1; while (w--) { if (ULLONG_MAX/p<=r) return ULLONG_MAX; r*=p; } return r; } int main() { // your code goes here unsigned long long n,k; char pop; scanf("%llu%llu",&n,&k); if(n<=62) { if(k>3ULL*(pow(2ULL,n)-1ULL)) {printf("NIE\n");return 0;} } if (k<=pow(2ULL,n)-1) pop='a'; else if (k>2*pow(2ULL,n)-1) pop='c'; else pop='b'; printf("%c",pop); while(k!=1ULL) { if(k<=pow(2ULL,n-1ULL)-1) { if(pop=='a') pop = 'b'; else pop = 'a'; } else { if(pop=='c') pop = 'b'; else pop = 'c'; k-=pow(2ULL,n-1ULL); } printf("%c",pop); n--; } printf("\n"); return 0; } |
English