fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7.  
  8. int t;
  9. cin >> t;
  10. while (t--) {
  11. int n, k;
  12. cin >> n >> k;
  13.  
  14. if (k == 1) {
  15. for (int i = 0; i < n; i++)
  16. cout << (i % 2 ? 'P' : 'A');
  17. cout << '\n';
  18. continue;
  19. }
  20.  
  21. if (k == 2 || k > n) {
  22. cout << "NIE\n";
  23. continue;
  24. }
  25.  
  26. string s = "";
  27. string a = string(k - 1, 'A') + 'P';
  28. string b = 'P' + string(k - 1, 'A');
  29.  
  30. bool flip = false;
  31.  
  32. while ((int)s.size() < n) {
  33. if (flip) s += b;
  34. else s += a;
  35. flip = !flip;
  36. }
  37.  
  38. s.resize(n);
  39. cout << s << '\n';
  40. }
  41. }
  42.  
Success #stdin #stdout 0.01s 5284KB
stdin
3
2 1
4 3
10 1
stdout
AP
AAPP
APAPAPAPAP