#include <bits/stdc++.h>
using namespace std;
int t, n, k;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin>>t;
while(t--) {
cin >> n >> k;
if(k == 1) {
if(n == 1) {
cout << "P\n";
}
else if(n==2) {
cout << "PA\n";
}
else {
cout << "NIE\n";
}
}
else if (k == 2) {
if(n==2) {
cout << "PP\n";
}
else if(n==3) {
cout << "PPA\n";
}
else if (n==4) {
cout << "PPAA\n";
}
else {
cout << "NIE\n";
}
}
else if (k == 3) {
if(n==3) {
cout << "PPP\n";
}
else if(n==4) {
cout << "PPPA\n";
}
else if (n==5) {
cout << "PPPAA\n";
}
else if (n==6) {
cout << "PPPAPA\n";
}
else if (n==7) {
cout << "PPPAPAA\n";
}
else if (n==8) {
cout << "PPPAPAAA\n";
}
else {
cout << "NIE\n";
}
}
else if (n == k) {
string res = "";
for(int i = 0; i < n; i++) {
res += "P";
}
cout << res << "\n";
}
else if (n == k + 1) {
string res = "";
for(int i = 0; i < n; i++) {
if(i == 0) {
res += "P";
}
else {
res += "A";
}
}
cout << res << "\n";
}
else {
string pattern = "PPAPAA";
string res = "";
while(res.size() < n) {
res += pattern;
}
while(n - (int)res.size() + 2 < k){
res.pop_back();
}
reverse(res.begin(), res.end());
while(res.size() < n) {
res += "P";
}
cout << res << "\n";
}
}
}
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 | #include <bits/stdc++.h> using namespace std; int t, n, k; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin>>t; while(t--) { cin >> n >> k; if(k == 1) { if(n == 1) { cout << "P\n"; } else if(n==2) { cout << "PA\n"; } else { cout << "NIE\n"; } } else if (k == 2) { if(n==2) { cout << "PP\n"; } else if(n==3) { cout << "PPA\n"; } else if (n==4) { cout << "PPAA\n"; } else { cout << "NIE\n"; } } else if (k == 3) { if(n==3) { cout << "PPP\n"; } else if(n==4) { cout << "PPPA\n"; } else if (n==5) { cout << "PPPAA\n"; } else if (n==6) { cout << "PPPAPA\n"; } else if (n==7) { cout << "PPPAPAA\n"; } else if (n==8) { cout << "PPPAPAAA\n"; } else { cout << "NIE\n"; } } else if (n == k) { string res = ""; for(int i = 0; i < n; i++) { res += "P"; } cout << res << "\n"; } else if (n == k + 1) { string res = ""; for(int i = 0; i < n; i++) { if(i == 0) { res += "P"; } else { res += "A"; } } cout << res << "\n"; } else { string pattern = "PPAPAA"; string res = ""; while(res.size() < n) { res += pattern; } while(n - (int)res.size() + 2 < k){ res.pop_back(); } reverse(res.begin(), res.end()); while(res.size() < n) { res += "P"; } cout << res << "\n"; } } } |
English