#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
string s1 = "AP";
string s2 = "AAPPP";
string s3 = "AAAPAPPP";
string s = "PAPPAA";
void test_case() {
int n, k;
cin >> n >> k;
// cerr << n << ' ' << k << ' ';
if (k < 4) {
if ((k == 1 && n > 2) || (k == 2 && n > 4) || (k == 3 && n > 8)) {
cout << "NIE" << endl;
return;
}
if (k == 1) cout << s1.substr(0, n);
if (k == 2) cout << s2.substr(0, n);
if (k == 3) cout << s3.substr(0, n);
cout << endl;
return;
}
for (int i = 0; i < k; i++){
cout << 'A';
}
for (int i = 0; i < n - k; i++) {
cout << s[i % 6];
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int q; cin >> q;
while (q--) {
test_case();
}
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 | #include <bits/stdc++.h> #define endl '\n' using namespace std; string s1 = "AP"; string s2 = "AAPPP"; string s3 = "AAAPAPPP"; string s = "PAPPAA"; void test_case() { int n, k; cin >> n >> k; // cerr << n << ' ' << k << ' '; if (k < 4) { if ((k == 1 && n > 2) || (k == 2 && n > 4) || (k == 3 && n > 8)) { cout << "NIE" << endl; return; } if (k == 1) cout << s1.substr(0, n); if (k == 2) cout << s2.substr(0, n); if (k == 3) cout << s3.substr(0, n); cout << endl; return; } for (int i = 0; i < k; i++){ cout << 'A'; } for (int i = 0; i < n - k; i++) { cout << s[i % 6]; } cout << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int q; cin >> q; while (q--) { test_case(); } return 0; } |
English