#include <bits/stdc++.h>
using namespace std;
#define pass (void)0
//#define int long long
//signed main(){
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--){
int n, k;
cin >> n >> k;
bool istnieje = true;
string res = "";
if((k==1 && n>=3) || (k==2 && n>=5) || (k==3 && n>=9)){
istnieje = false;
}
string subres = "";
if(k==1){
subres="PA";
}
else if(k==2){
subres = "PPAA";
}
else if(k==3){
subres = "AAAPAPPP";
}
else if(k==4){
subres = "APPAPA";
}
else if(k>=5){
subres = 'P' + string(k-2, 'A') + string(k-3, 'P') + 'A';
}
while(res.size() < n){
res += subres;
}
res = res.substr(0, n);
if(istnieje){
cout << res;
}
else{
cout << "NIE";
}
if(t){
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 53 54 | #include <bits/stdc++.h> using namespace std; #define pass (void)0 //#define int long long //signed main(){ int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while(t--){ int n, k; cin >> n >> k; bool istnieje = true; string res = ""; if((k==1 && n>=3) || (k==2 && n>=5) || (k==3 && n>=9)){ istnieje = false; } string subres = ""; if(k==1){ subres="PA"; } else if(k==2){ subres = "PPAA"; } else if(k==3){ subres = "AAAPAPPP"; } else if(k==4){ subres = "APPAPA"; } else if(k>=5){ subres = 'P' + string(k-2, 'A') + string(k-3, 'P') + 'A'; } while(res.size() < n){ res += subres; } res = res.substr(0, n); if(istnieje){ cout << res; } else{ cout << "NIE"; } if(t){ cout << "\n"; } } } |
English