#include <vector> #include <list> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <cstring> #include <cassert> #define FOR(i,b,e) for(int i=(b);i<(e);++i) #define FORQ(i,b,e) for(int i=(b);i<=(e);++i) #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i) #define REP(x, n) for(int x = 0; x < (n); ++x) #define PB push_back #define LL long long #define MP make_pair #define ST first #define ND second using namespace std; #define MR 1000010 LL k; int n, pos, prevV; void go() { if (!k) return; assert( pos <= n ); LL val = ( n - pos + 1 >= 62 ? 1LL << 62 : 1LL << ( n - pos + 1 ) ) - 1; if (val < k) { k -= val; if (val < k) { assert( prevV == -1 ); k -= val; if (val < k) printf( "NIE" ); else { printf("c"); pos++; k--; prevV = 2; go(); } } else { char first = prevV == 2 ? 'b' : 'c'; printf( "%c", first ); pos++; k--; prevV = first - 'a'; go(); } } else { char first = prevV ? 'a' : 'b'; printf( "%c", first ); pos++; k--; prevV = first - 'a'; go(); } } int main() { scanf( "%d%lld", &n, &k ); pos = 1; prevV = -1; go(); 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | #include <vector> #include <list> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <cstring> #include <cassert> #define FOR(i,b,e) for(int i=(b);i<(e);++i) #define FORQ(i,b,e) for(int i=(b);i<=(e);++i) #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i) #define REP(x, n) for(int x = 0; x < (n); ++x) #define PB push_back #define LL long long #define MP make_pair #define ST first #define ND second using namespace std; #define MR 1000010 LL k; int n, pos, prevV; void go() { if (!k) return; assert( pos <= n ); LL val = ( n - pos + 1 >= 62 ? 1LL << 62 : 1LL << ( n - pos + 1 ) ) - 1; if (val < k) { k -= val; if (val < k) { assert( prevV == -1 ); k -= val; if (val < k) printf( "NIE" ); else { printf("c"); pos++; k--; prevV = 2; go(); } } else { char first = prevV == 2 ? 'b' : 'c'; printf( "%c", first ); pos++; k--; prevV = first - 'a'; go(); } } else { char first = prevV ? 'a' : 'b'; printf( "%c", first ); pos++; k--; prevV = first - 'a'; go(); } } int main() { scanf( "%d%lld", &n, &k ); pos = 1; prevV = -1; go(); printf( "\n" ); return 0; } |