#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "lib/debug.h"
#else
#define debug(...) 228
#endif
typedef long long ll;
typedef long double ld;
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
vector<int> read_vec(int n) {
vector<int> v(n);
for (int &t: v) cin >> t;
return v;
}
template<typename T>
inline void upd_max(T &a, T b) {
if (a < b) {
a = b;
}
}
template<typename T>
inline void upd_min(T &a, T b) {
if (a > b) {
a = b;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
int tst;
cin >> tst;
while (tst--) {
int n, k;
cin >> n >> k;
if (k <= 3) {
string f;
if (k == 1) f = "AP";
else if (k == 2) f = "AAPP";
else {
f = "AAAPAPPP";
}
if (n <= f.size()) {
cout << f.substr(0, n) << '\n';
} else {
cout << "NIE\n";
}
}
else {
string t(k, 'A');
FOR(i, 0, n - k) {
t += "PAPPAA"[i % 6];
}
cout << t << '\n';
}
}
/*
int mn = 20;
FOR(i, 0, 1 << 8) {
string s;
FOR(x, 0, 8) {
if ((i >> x) & 1) s += 'A';
else s += 'P';
}
int max_pal = 0;
FOR(a, 0, 8) {
FOR(b, a, 8) {
string f = s.substr(a, b - a + 1);
string tf(f.rbegin(), f.rend());
if (f == tf) upd_max(max_pal, b - a + 1);
}
}
if (max_pal == 3) cout << s << '\n';
upd_min(mn, max_pal);
}
cout << mn << '\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 98 99 | #ifdef DEBUG #define _GLIBCXX_DEBUG #endif //#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; #ifdef DEBUG #include "lib/debug.h" #else #define debug(...) 228 #endif typedef long long ll; typedef long double ld; #define pb push_back #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) vector<int> read_vec(int n) { vector<int> v(n); for (int &t: v) cin >> t; return v; } template<typename T> inline void upd_max(T &a, T b) { if (a < b) { a = b; } } template<typename T> inline void upd_min(T &a, T b) { if (a > b) { a = b; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef DEBUG freopen("input.txt", "r", stdin); #endif int tst; cin >> tst; while (tst--) { int n, k; cin >> n >> k; if (k <= 3) { string f; if (k == 1) f = "AP"; else if (k == 2) f = "AAPP"; else { f = "AAAPAPPP"; } if (n <= f.size()) { cout << f.substr(0, n) << '\n'; } else { cout << "NIE\n"; } } else { string t(k, 'A'); FOR(i, 0, n - k) { t += "PAPPAA"[i % 6]; } cout << t << '\n'; } } /* int mn = 20; FOR(i, 0, 1 << 8) { string s; FOR(x, 0, 8) { if ((i >> x) & 1) s += 'A'; else s += 'P'; } int max_pal = 0; FOR(a, 0, 8) { FOR(b, a, 8) { string f = s.substr(a, b - a + 1); string tf(f.rbegin(), f.rend()); if (f == tf) upd_max(max_pal, b - a + 1); } } if (max_pal == 3) cout << s << '\n'; upd_min(mn, max_pal); } cout << mn << '\n'; */ return 0; } |
English