#include<bits/stdc++.h>
using namespace std;
using ll = long long;
string nastr(int n, int x){
string s;
for(int i = 0; i < n; i++){
if(x & (1 << i))s.push_back('P');
else s.push_back('A');
}
return s;
}
int CCC(string v){
int n = v.size();
int maks = 0;
for(int a = 0; a < n; a++){
for(int b = a; b < n; b++){
bool ok = 1;
for(int c = a; c <= b; c++){
if(v[c] != v[b - c + a]){
ok = 0;
break;
}
}
if(ok)maks = max(maks, b - a + 1);
}
}
return maks;
}
string ans[10];
void solve(){
int n, k;
cin >> n >> k;
// cout << n << " " << k << '\n';
if(k == 4){
///dodajewoijoifjewfoiewqjfoiewjfiewjfewjfjwqoijfiewqfwoijfoqiwjfeoijewqoifjewjfoiwe
string w;
while(w.size() <= n){
//1111 0010 1100 1011 0010
w += "APPAPAAPPAPA";
}
while(w.size() > n)w.pop_back();
cout << w << '\n';
return;
}
if(k <= 3){
if(n >= 10){
cout << "NIE\n";
return;
}
else{
for(int i = 0; i < (1 << n); i++){
if(CCC(nastr(n,i)) == k){
cout << nastr(n,i) << '\n';
return;
}
}
}
cout << "NIE\n";
return;
}
if(k > n/2){
for(int i = 0; i < k; i++)cout << "A";
for(int i = k; i < n; i++)cout << "P";
cout << '\n';
return;
}
if(k <= 8){
string w;
while(w.size() <= n){
w += ans[k];
}
while(w.size() > n)w.pop_back();
cout << w << '\n';
return;
}
string x = "APA";
for(int i = 3; i < k; i++)x += "A";
x += "P";
for(int i = 7; i < k; i++)x += "PPAA";
while(x.size() >= 2*k)x.pop_back();
string w;
while(w.size() <= n){
w += x;
}
while(w.size() > n)w.pop_back();
cout << w << endl;
}
int main(){
ans[5] = "APAAAPPPAP";
ans[6] = "APAAAAPPPAPA";
ans[7] = "APAAAAAPPPAPAA";
ans[8] = "APAAAAAAPPAPAPAA";
int tt;
cin >> tt;
while(tt--)solve();
}
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | #include<bits/stdc++.h> using namespace std; using ll = long long; string nastr(int n, int x){ string s; for(int i = 0; i < n; i++){ if(x & (1 << i))s.push_back('P'); else s.push_back('A'); } return s; } int CCC(string v){ int n = v.size(); int maks = 0; for(int a = 0; a < n; a++){ for(int b = a; b < n; b++){ bool ok = 1; for(int c = a; c <= b; c++){ if(v[c] != v[b - c + a]){ ok = 0; break; } } if(ok)maks = max(maks, b - a + 1); } } return maks; } string ans[10]; void solve(){ int n, k; cin >> n >> k; // cout << n << " " << k << '\n'; if(k == 4){ ///dodajewoijoifjewfoiewqjfoiewjfiewjfewjfjwqoijfiewqfwoijfoqiwjfeoijewqoifjewjfoiwe string w; while(w.size() <= n){ //1111 0010 1100 1011 0010 w += "APPAPAAPPAPA"; } while(w.size() > n)w.pop_back(); cout << w << '\n'; return; } if(k <= 3){ if(n >= 10){ cout << "NIE\n"; return; } else{ for(int i = 0; i < (1 << n); i++){ if(CCC(nastr(n,i)) == k){ cout << nastr(n,i) << '\n'; return; } } } cout << "NIE\n"; return; } if(k > n/2){ for(int i = 0; i < k; i++)cout << "A"; for(int i = k; i < n; i++)cout << "P"; cout << '\n'; return; } if(k <= 8){ string w; while(w.size() <= n){ w += ans[k]; } while(w.size() > n)w.pop_back(); cout << w << '\n'; return; } string x = "APA"; for(int i = 3; i < k; i++)x += "A"; x += "P"; for(int i = 7; i < k; i++)x += "PPAA"; while(x.size() >= 2*k)x.pop_back(); string w; while(w.size() <= n){ w += x; } while(w.size() > n)w.pop_back(); cout << w << endl; } int main(){ ans[5] = "APAAAPPPAP"; ans[6] = "APAAAAPPPAPA"; ans[7] = "APAAAAAPPPAPAA"; ans[8] = "APAAAAAAPPAPAPAA"; int tt; cin >> tt; while(tt--)solve(); } |
English