#include<cstdio> #include<cstring> #include<algorithm> #include<queue> #define REP(i,n) for(int i=0;i<(n);++i) #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define FORD(i,a,b) for(int i=(a);i>=(b);--i) #define foreach(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) #define all(c) (c).begin(),(c).end() #define scanf(...) scanf(__VA_ARGS__)?:0 #define e1 first #define e2 second #define mp make_pair using namespace std; typedef long long ll; typedef pair<int,int> pii; int n; ll k,d[34]; char zn,ost='d'; int main() { scanf("%d%lld",&n,&k); if (n<62 && k>3*(1ll<<n)-3) puts("NIE"),exit(0); while (k>0) { zn='a'; k--; while (n<62 && k>=(1ll<<n)-1) k-=(1ll<<n)-1,zn++; if (zn>=ost) zn++; putchar(zn); ost=zn; n--; } }
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 | #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #define REP(i,n) for(int i=0;i<(n);++i) #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define FORD(i,a,b) for(int i=(a);i>=(b);--i) #define foreach(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) #define all(c) (c).begin(),(c).end() #define scanf(...) scanf(__VA_ARGS__)?:0 #define e1 first #define e2 second #define mp make_pair using namespace std; typedef long long ll; typedef pair<int,int> pii; int n; ll k,d[34]; char zn,ost='d'; int main() { scanf("%d%lld",&n,&k); if (n<62 && k>3*(1ll<<n)-3) puts("NIE"),exit(0); while (k>0) { zn='a'; k--; while (n<62 && k>=(1ll<<n)-1) k-=(1ll<<n)-1,zn++; if (zn>=ost) zn++; putchar(zn); ost=zn; n--; } } |