#include <iostream> #include <math.h> using namespace std; char first(char c) { if (c=='a') return 'b'; else return 'a'; } char second(char c) { if (c=='c') return 'b'; else return 'c'; } int main() { long long unsigned int k; long long unsigned int n; scanf("%lld %lld", &n, &k); long long int p ; char prev = 'z'; string output; for (int i=0;i<n;i++) { k--; if (n-i>63) { char k = first(prev); output.push_back(k); prev = k; continue; } p = pow(2, n-i)-1; if (k>=3*p) { cout << "NIE" << endl; return 0; } if (prev=='z') { output.push_back(char(int('a') + k/p)); prev = char(int('a') + k/p); } else { if (k/p == 0) { char k = first(prev); output.push_back(k); prev = k; } else { char k = second(prev); output.push_back(k); prev = k; } } if (k% p == 0) { cout << output; return 0; } k = k% p; } cout << output << endl; 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #include <iostream> #include <math.h> using namespace std; char first(char c) { if (c=='a') return 'b'; else return 'a'; } char second(char c) { if (c=='c') return 'b'; else return 'c'; } int main() { long long unsigned int k; long long unsigned int n; scanf("%lld %lld", &n, &k); long long int p ; char prev = 'z'; string output; for (int i=0;i<n;i++) { k--; if (n-i>63) { char k = first(prev); output.push_back(k); prev = k; continue; } p = pow(2, n-i)-1; if (k>=3*p) { cout << "NIE" << endl; return 0; } if (prev=='z') { output.push_back(char(int('a') + k/p)); prev = char(int('a') + k/p); } else { if (k/p == 0) { char k = first(prev); output.push_back(k); prev = k; } else { char k = second(prev); output.push_back(k); prev = k; } } if (k% p == 0) { cout << output; return 0; } k = k% p; } cout << output << endl; return 0; } |