#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int N=1e5+5;
#define gc getchar_unlocked
#define pc putchar_unlocked
inline int read(){
int x=0; char c=gc();
while(!isdigit(c))c=gc();
while(isdigit(c))x=x*10+c-'0',c=gc();
return x;
}
int n,k;
int main(){
int T=read();
while(T--){
n=read(),k=read();
bool fl=0;
if(n<=10){
for(int s=0;s<(1<<n);s++){
static char str[100];
for(int i=0;i<n;i++)str[i]="PA"[(s>>i)&1];
str[n]=0;
int maxn=0;
for(int l=0;l<n;l++){
for(int r=l;r<n;r++){
bool f=1;
for(int p=l,q=r;p<q;p++,q--)f&=str[p]==str[q];
if(f)maxn=max(maxn,r-l+1);
}
}
if(maxn==k){
for(int i=0;i<n;i++)pc(str[i]);
fl=1;
break;
}
}
}
else if(k>3){
fl=1;
for(int i=0;i<k;i++)pc('A');
for(int i=0;i<n-k;i++)pc("PAPPAA"[i%6]);
}
if(!fl)pc('N'),pc('I'),pc('E');
pc('\n');
}
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 | #include<bits/stdc++.h> using namespace std; typedef long long ll; constexpr int N=1e5+5; #define gc getchar_unlocked #define pc putchar_unlocked inline int read(){ int x=0; char c=gc(); while(!isdigit(c))c=gc(); while(isdigit(c))x=x*10+c-'0',c=gc(); return x; } int n,k; int main(){ int T=read(); while(T--){ n=read(),k=read(); bool fl=0; if(n<=10){ for(int s=0;s<(1<<n);s++){ static char str[100]; for(int i=0;i<n;i++)str[i]="PA"[(s>>i)&1]; str[n]=0; int maxn=0; for(int l=0;l<n;l++){ for(int r=l;r<n;r++){ bool f=1; for(int p=l,q=r;p<q;p++,q--)f&=str[p]==str[q]; if(f)maxn=max(maxn,r-l+1); } } if(maxn==k){ for(int i=0;i<n;i++)pc(str[i]); fl=1; break; } } } else if(k>3){ fl=1; for(int i=0;i<k;i++)pc('A'); for(int i=0;i<n-k;i++)pc("PAPPAA"[i%6]); } if(!fl)pc('N'),pc('I'),pc('E'); pc('\n'); } return 0; } |
English