#include <bits/stdc++.h>
using namespace std;
string repete(string x, int n){
string ans="";
for(int i=0; i<n; i++) ans += x;
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
for(int _=0; _<t; _++){
int n, k;
cin >> n >> k;
if(k == 1){
if(n == 1) cout << "P";
else if(n == 2) cout << "PA";
else cout << "NIE";
} else if(k == 2){
if(n > 4) cout << "NIE";
else{
string ans = "AAPP";
for(int i=0; i<n; i++) cout << ans[i];
}
} else if(k == 3){
if(n > 8) cout << "NIE";
else{
string ans = "AAAPAPPP";
for(int i=0; i<n; i++) cout << ans[i];
}
} else {
string ans = repete("A", k);
while(int(ans.size()) < n){
ans += "PAPP";
ans += repete("A", k-2);
}
for(int i=0; i<n; i++) cout << ans[i];
}
cout << "\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 | #include <bits/stdc++.h> using namespace std; string repete(string x, int n){ string ans=""; for(int i=0; i<n; i++) ans += x; return ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; for(int _=0; _<t; _++){ int n, k; cin >> n >> k; if(k == 1){ if(n == 1) cout << "P"; else if(n == 2) cout << "PA"; else cout << "NIE"; } else if(k == 2){ if(n > 4) cout << "NIE"; else{ string ans = "AAPP"; for(int i=0; i<n; i++) cout << ans[i]; } } else if(k == 3){ if(n > 8) cout << "NIE"; else{ string ans = "AAAPAPPP"; for(int i=0; i<n; i++) cout << ans[i]; } } else { string ans = repete("A", k); while(int(ans.size()) < n){ ans += "PAPP"; ans += repete("A", k-2); } for(int i=0; i<n; i++) cout << ans[i]; } cout << "\n"; } } |
English