#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
#define pii pair<int,int>
#define vii vector<pair<int,int>>
#define vi vector<int>
#define pll pair<ll, ll>
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define count_bits(x) __builtin_popcountll((x))
const ll M = 1e9+7;
const ll INF = 1e9;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
void solve(){
int n, k;
cin >> n >> k;
if(k == 1){
if(n == 1){
cout << "A\n";
}
else if(n == 2){
cout << "AP\n";
}
else{
cout << "NIE\n";
}
}
else if(k == 2){
if(n== 2){
cout << "AA\n";
}
else if(n == 3){
cout << "AAP\n";
}
else if(n == 4){
cout << "AAPP\n";
}
else{
cout << "NIE\n";
}
}
else if(k == 3){
if(n == 3){
cout << "AAA\n";
}
else if(n == 4){
cout << "AAAP\n";
}
else if(n == 5){
cout << "AAAPP\n";
}
else if(n == 6){
cout << "AAAPPP\n";
}
else if(n == 7){
cout << "AAAPAPP\n";
}
else if(n == 8){
cout << "AAAPAPPP\n";
}
else{
cout << "NIE\n";
}
}
else{
string s;
for(int i = 0; i < k; ++i){
s += 'A';
}
n -= k;
int it = 0;
string wzor = "PAPPAA";
while(n--){
s += wzor[it];
it = (it + 1) % wzor.size();
}
cout << s << "\n";
}
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
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 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 | #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; #define pii pair<int,int> #define vii vector<pair<int,int>> #define vi vector<int> #define pll pair<ll, ll> #define all(x) (x).begin(),(x).end() #define siz(x) (int)(x).size() #define count_bits(x) __builtin_popcountll((x)) const ll M = 1e9+7; const ll INF = 1e9; //mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());} //ll los(ll a, ll b) {return a + (mt() % (b-a+1));} typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; void solve(){ int n, k; cin >> n >> k; if(k == 1){ if(n == 1){ cout << "A\n"; } else if(n == 2){ cout << "AP\n"; } else{ cout << "NIE\n"; } } else if(k == 2){ if(n== 2){ cout << "AA\n"; } else if(n == 3){ cout << "AAP\n"; } else if(n == 4){ cout << "AAPP\n"; } else{ cout << "NIE\n"; } } else if(k == 3){ if(n == 3){ cout << "AAA\n"; } else if(n == 4){ cout << "AAAP\n"; } else if(n == 5){ cout << "AAAPP\n"; } else if(n == 6){ cout << "AAAPPP\n"; } else if(n == 7){ cout << "AAAPAPP\n"; } else if(n == 8){ cout << "AAAPAPPP\n"; } else{ cout << "NIE\n"; } } else{ string s; for(int i = 0; i < k; ++i){ s += 'A'; } n -= k; int it = 0; string wzor = "PAPPAA"; while(n--){ s += wzor[it]; it = (it + 1) % wzor.size(); } cout << s << "\n"; } } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while(t--){ solve(); } return 0; } |
English