#include <iostream>
#include <map>
using namespace std;
using ll = long long;
map<pair<ll, ll>, string> three_or_less = {
{{1, 1}, "A"},
{{2, 1}, "AP"},
{{2, 2}, "AA"},
{{3, 2}, "AAP"},
{{3, 3}, "AAA"},
{{4, 2}, "AAPP"},
{{4, 3}, "AAAP"},
{{5, 3}, "AAAPA"},
{{6, 3}, "AAAPAP"},
{{7, 3}, "AAAPAPP"},
{{8, 3}, "AAAPAPPP"},
};
constexpr string loop = "AAPAPP";
void test_case() {
ll n, k;
cin >> n >> k;
if (k <= 3) {
if (three_or_less.contains({n, k})) {
cout << three_or_less[{n, k}] << "\n";
} else {
cout << "NIE\n";
}
return;
} else {
cout << std::string(k, 'P');
for(int i = 0; i < (n - k) / 6; i++) {
cout << loop;
}
cout << std::string(loop, 0, (n - k) % 6) << "\n";
return;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll t;
cin >> t;
while(t-->0) {
test_case();
}
}
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 | #include <iostream> #include <map> using namespace std; using ll = long long; map<pair<ll, ll>, string> three_or_less = { {{1, 1}, "A"}, {{2, 1}, "AP"}, {{2, 2}, "AA"}, {{3, 2}, "AAP"}, {{3, 3}, "AAA"}, {{4, 2}, "AAPP"}, {{4, 3}, "AAAP"}, {{5, 3}, "AAAPA"}, {{6, 3}, "AAAPAP"}, {{7, 3}, "AAAPAPP"}, {{8, 3}, "AAAPAPPP"}, }; constexpr string loop = "AAPAPP"; void test_case() { ll n, k; cin >> n >> k; if (k <= 3) { if (three_or_less.contains({n, k})) { cout << three_or_less[{n, k}] << "\n"; } else { cout << "NIE\n"; } return; } else { cout << std::string(k, 'P'); for(int i = 0; i < (n - k) / 6; i++) { cout << loop; } cout << std::string(loop, 0, (n - k) % 6) << "\n"; return; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll t; cin >> t; while(t-->0) { test_case(); } } |
English