#include <iostream>
using namespace std;
const string BLOCK = "AAPAPP";
const string K3_BASE = "AAAPAPPP";
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t; cin >> t;
while (t--)
{
int n, k;
cin >> n >> k;
if (k == 1)
{
if (n == 1) cout << "A" << endl;
else if (n == 2) cout << "AP" << endl;
else cout << "NIE" << endl;
continue;
}
if (k == 2)
{
if (n == 2) cout << "AA" << endl;
else if (n == 3) cout << "AAP" << endl;
else if (n == 4) cout << "AAPP" << endl;
else cout << "NIE" << endl;
continue;
}
if (k == 3)
{
if (n<=8) cout<<K3_BASE.substr(0, n)<<endl;
else cout << "NIE" << endl;
continue;
}
string ans;
ans.reserve(n);
ans.append(k - 2, 'A');
while (ans.size() < n)
{
int need = n - ans.size();
ans += BLOCK.substr(0, min(need, (int)BLOCK.size()));
}
cout << ans << endl;
}
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 | #include <iostream> using namespace std; const string BLOCK = "AAPAPP"; const string K3_BASE = "AAAPAPPP"; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; if (k == 1) { if (n == 1) cout << "A" << endl; else if (n == 2) cout << "AP" << endl; else cout << "NIE" << endl; continue; } if (k == 2) { if (n == 2) cout << "AA" << endl; else if (n == 3) cout << "AAP" << endl; else if (n == 4) cout << "AAPP" << endl; else cout << "NIE" << endl; continue; } if (k == 3) { if (n<=8) cout<<K3_BASE.substr(0, n)<<endl; else cout << "NIE" << endl; continue; } string ans; ans.reserve(n); ans.append(k - 2, 'A'); while (ans.size() < n) { int need = n - ans.size(); ans += BLOCK.substr(0, min(need, (int)BLOCK.size())); } cout << ans << endl; } return 0; } |
English