#include <bits/stdc++.h> using namespace std; const int R = 1e6 + 1; const int Z[3][2] = {{'b','c'},{'a','c'},{'a','b'}}; const long long I = 1000000000000000001; char s[R]; int main(){ int n; long long k; scanf("%d%lld",&n,&k); long long x; if(n > 59)x = I; else x = (1LL << n) - 1; if(k > x){ k -= x; if(k > x){ k -= x; if(k > x){ puts("NIE"); return 0; } else s[0] = 'c'; } else s[0] = 'b'; } else s[0] = 'a'; for(int i=1;i<n;i++){ if(k > 1){ --k; long long x; if(n - i > 59)x = I; else x = (1LL << (n-i)) - 1; if(k > x){ k -= x; s[i] = Z[s[i-1]-'a'][1]; } else s[i] = Z[s[i-1]-'a'][0]; } else break; } printf("%s",s); 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 | #include <bits/stdc++.h> using namespace std; const int R = 1e6 + 1; const int Z[3][2] = {{'b','c'},{'a','c'},{'a','b'}}; const long long I = 1000000000000000001; char s[R]; int main(){ int n; long long k; scanf("%d%lld",&n,&k); long long x; if(n > 59)x = I; else x = (1LL << n) - 1; if(k > x){ k -= x; if(k > x){ k -= x; if(k > x){ puts("NIE"); return 0; } else s[0] = 'c'; } else s[0] = 'b'; } else s[0] = 'a'; for(int i=1;i<n;i++){ if(k > 1){ --k; long long x; if(n - i > 59)x = I; else x = (1LL << (n-i)) - 1; if(k > x){ k -= x; s[i] = Z[s[i-1]-'a'][1]; } else s[i] = Z[s[i-1]-'a'][0]; } else break; } printf("%s",s); return 0; } |