#include <bits/stdc++.h> using namespace std; #define PB push_back #define FORE(i, t) for(__typeof(t.begin())i=t.begin();i!=t.end();++i) #define SZ(x) int((x).size()) #define REP(i, n) for(int i=0,_=(n);i<_;++i) #define FOR(i, a, b) for(int i=(a),_=(b);i<=_;++i) #define FORD(i, a, b) for(int i=(a),_=(b);i>=_;--i) typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; const int INF = 1e9 + 9; const ll LLINF = 3e18 + 9; ll F[70] = {0, 3}, max_F_id; int next_char[4][3] = { {1, 2}, {0, 2}, {0, 1}, {0, 1, 2}, }; void init_F() { for (int i = 2;;++i) { F[i] = 2LL * F[i - 1] + 3; if (F[i] > LLINF) { max_F_id = i; break; } } } ll f(int x) { if (x > max_F_id) { return F[max_F_id]; } return F[x]; } void reconstruct(int last, int n, ll k) { // cout << "last: " << last << " n: " << n << " k: " << k << "\n"; for (;;) { if (k == 0) { return; } --k; ll third = f(n) / 3; int part = k / third; last = next_char[last][part]; cout << "abc"[last]; --n; k %= third; } } void inline one() { init_F(); REP (i, 70) { // cout << i << ": " << f(i) << "\n"; } int n; ll k; cin >> n >> k; if (k > f(n)) { puts("NIE"); return; } reconstruct(3, n, k); cout << "\n"; } int main() { ios::sync_with_stdio(false); //int z; cin >> z; while(z--) one(); }
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 | #include <bits/stdc++.h> using namespace std; #define PB push_back #define FORE(i, t) for(__typeof(t.begin())i=t.begin();i!=t.end();++i) #define SZ(x) int((x).size()) #define REP(i, n) for(int i=0,_=(n);i<_;++i) #define FOR(i, a, b) for(int i=(a),_=(b);i<=_;++i) #define FORD(i, a, b) for(int i=(a),_=(b);i>=_;--i) typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; const int INF = 1e9 + 9; const ll LLINF = 3e18 + 9; ll F[70] = {0, 3}, max_F_id; int next_char[4][3] = { {1, 2}, {0, 2}, {0, 1}, {0, 1, 2}, }; void init_F() { for (int i = 2;;++i) { F[i] = 2LL * F[i - 1] + 3; if (F[i] > LLINF) { max_F_id = i; break; } } } ll f(int x) { if (x > max_F_id) { return F[max_F_id]; } return F[x]; } void reconstruct(int last, int n, ll k) { // cout << "last: " << last << " n: " << n << " k: " << k << "\n"; for (;;) { if (k == 0) { return; } --k; ll third = f(n) / 3; int part = k / third; last = next_char[last][part]; cout << "abc"[last]; --n; k %= third; } } void inline one() { init_F(); REP (i, 70) { // cout << i << ": " << f(i) << "\n"; } int n; ll k; cin >> n >> k; if (k > f(n)) { puts("NIE"); return; } reconstruct(3, n, k); cout << "\n"; } int main() { ios::sync_with_stdio(false); //int z; cin >> z; while(z--) one(); } |