Problem:
Problem A:
Ginkgo Numbers
We will define Ginkgo numbers and multiplication on Ginkgo numbers.
A
Ginkgo number
is a pair <
m
,
n
> where
m
and
n
are integers. For example, <1, 1>, <-2, 1> and <-3,-1> are Ginkgo numbers.
The multiplication on Ginkgo numbers is defined by <
m
,
n
> · <
x
,
y
> = <
mx
−
ny
,
my
+
nx
>. For example, <1, 1> · <-2, 1> = <-3,-1>.
A Ginkgo number <
m
,
n
> is called a divisor of a Ginkgo number <
p
,
q
> if there exists a Ginkgo number <
x
,
y
> such that <
m
,
n
> · <
x
,
y
> = <
p
,
q
>.
For any Ginkgo number <
m
,
n
>, Ginkgo numbers <1, 0>, <0, 1>, <-1, 0>, <0,-1>, <
m
,
n
>, <-
n
,
m
>, <-
m
,-
n
> and <
n
,-
m
> are divisors of <
m
,
n
>. If
m
2
+
n
2
> 1, these Ginkgo numbers are distinct. In other words, any Ginkgo number such that
m
2
+
n
2
> 1 has at least eight divisors.
A Ginkgo number <
m
,
n
> is called a prime if
m
2
+
n
2
> 1 and it has exactly eight divisors. Your mission is to check whether a given Ginkgo number is a prime or not.
The following two facts might be useful to check whether a Ginkgo number is a divisor of another Ginkgo number.
Suppose
m
2
+
n
2
> 0. Then, <
m
,
n
> is a divisor of <
p
,
q
> if and only if the integer
m
2
+
n
2
is a common divisor of
mp
+
nq
and
mq
−
np
.
If <
m
,
n
> · <
x
,
y
> = <
p
,
q
>, then (
m
2
+
n
2
)(
x
2
+
y
2
) =
p
2
+
q
2
.
Input
The first line of the input contains a single integer, which is the number of datasets.
The rest of the input is a sequence of datasets. Each dataset is a line containing two integers
m
and
n
, separated by a space. They designate the Ginkgo number <
m
,
n
>. You can assume 1 <
m
2
+
n
2
< 20000.
Output
For each dataset, output a character '
P
' in a line if the Ginkgo number is a prime. Output a character '
C
' in a line otherwise.
Sample Input
8
10 0
0 2
-3 0
4 2
0 -13
-4 1
-2 -1
3 -1
Output for the Sample Input
C
C
P
C
C
P
P
C

Submitted solutions:

code_snippet: #include<cstring>
#include<string>
#include<sstream>
#include<fstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<ctime>
#include<cstdlib>
#include<functional>
#include<cmath>
using namespace std;
#define PI acos(-1.0)
#define eps 1e-7
#define INF 0x3F3F3F3F      //0x7FFFFFFF
#define LLINF 0x7FFFFFFFFFFFFFFF
#define seed 1313131
#define MOD 1000000007
#define ll long long
#define ull unsigned ll
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int main ()
{
    int N;
    scanf("%d",&N);
    while(N--)
    {
        int p,q;
        scanf("%d%d",&p,&q);

        int flag = 1;
        for(int m=-150; m<150; m++)
        {
            if(flag == 0 ) break;
            for(int n=-150; n<150; n++)
            {
                if(m==0&&n==1)  continue;
                if(m==0&&n==-1)  continue;
                if(m==1&&n==0) continue;
                if(m==-1&&n==0) continue;
                if(m==p&&n==q) continue;
                if(m==-p&&n==-q) continue;
                if(m==-q&&n==p) continue;
                if(m==q&&n==-p) continue;
                if(m==0&&n==0) continue;

                int num =m*m+n*n;
                int he1 = m*p+n*q;
                int he2 = m*q-n*p;
                if(he1%num==0&&he2%num==0)
                {
                    flag = 0;
                    break;
                }
            }
        }
        if(flag == 0) printf("C\n");
        else printf("P\n");
    }

}
accuracy: 1
time_ms: 20
memory_kb: 3380
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) a.begin(),a.end()
#define reps(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, a, n) for (int i = (a); i > (int)(n); i--)
const long long mod = 1000000007;
const long long INF = 1e18;
ll myceil(ll a, ll b) {return (a+b-1)/b;}


void solve() {
    int n,m;
    cin >> m >> n;

    int mx = n*n + m*m;

    reps(i,-150,150) {
        reps(j,-150,150) {
            if (i*i + j*j <= mx) {
                if ((i == 0 && j == 0) || (i == 1 && j == 0) || (i == 0 && j == 1) || (i == -1 && j == 0) || (i == 0 && j == -1) || (i == m && j == n) ||(i == -n && j == m) || (i == -m && j == -n) || (i == n && j == -m)) continue;
                if (gcd(i*m+j*n,i*n-j*m)%(i*i+j*j) == 0) {
                    cout << 'C' << endl;
                    return;
                }
            }
        }
    }

    cout << 'P' << endl;
    return;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    rep(i,t) {
        solve();
    }
}
accuracy: 1
time_ms: 80
memory_kb: 3388
final_rank: 15

code_snippet: #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

bool isPrime(int m, int n) {
	for (int d = -142; d <= 142; d++) {
		for (int e = -142; e <= 142; e++) {
			int d2pe2 = d * d + e * e;
			if (d2pe2 <= 1 || 20000 <= d2pe2 || d == m && e == n || d == -n && e == m || d == -m && e == -n || d == n && e == -m) continue;

			if ((d * m + e * n) % d2pe2 == 0 && (d * n - e * m) % d2pe2 == 0) return false;
		}
	}

	return true;
}

int main() {
	int numof_data;
	cin >> numof_data;

	for (int data = 0; data < numof_data; data++) {
		int m, n;
		cin >> m >> n;

		if (isPrime(m, n)) {
			cout << "P" << endl;
		} else {
			cout << "C" << endl;
		}
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3336
final_rank: 8

code_snippet: // author: hanyu
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int t;
  cin >> t;

  while (t--) {
    int m, n;
    cin >> m >> n;

    int lim = max(abs(n), abs(m)), count = 0;
    for (int i = -lim; i <= lim; i++) {
      for (int j = -lim; j <= lim; j++) {
        if (i == 0 && j == 0) continue;
        int tmp = i * i + j * j;
        int x = m * i + n * j, y = n * i - m * j;
        if (x % tmp == 0 && y % tmp == 0) count++;
      }
    }

    if (count == 8) cout << "P" << endl;
    else cout << "C" << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3256
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rrep(i,l,r) for(int i=l;i<=r;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#define unq(x) sort(all(x));x.erase(unique(all(x)),x.end())
//#define mod 1000000007
#define mod 998244353
//ll mod;
#define ad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
void readv(vector<ll> &a,ll n){
	rep(i,n){
		ll x;
		cin>>x;
		a.push_back(x);
	}
}
void outv(vector<ll> &a,ll n){
	rep(i,n){
		if(i>0)cout<<" ";
		cout<<a[i];
	}
	cout<<"\n";
}
ll po(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
ll gcd(ll a,ll b){
	return (b?gcd(b,a%b):a);
}
#define FACMAX 200010
ll fac[FACMAX],inv[FACMAX],ivf[FACMAX];
void initfac(){
	fac[0]=ivf[0]=inv[1]=1;
	for(ll i=1;i<FACMAX;i++)fac[i]=fac[i-1]*i%mod;
	for(ll i=1;i<FACMAX;i++){
		if(i>1)inv[i]=(mod-mod/i*inv[mod%i]%mod)%mod;
		ivf[i]=po(fac[i],mod-2);
	}
}
ll P(ll n,ll k){
	if(n<0||n<k)return 0;
	return fac[n]*ivf[n-k]%mod;
}
ll C(ll n,ll k){
	if(k<0||n<k)return 0;
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
ll H(ll n,ll k){
	return C(n+k-1,k);
}

ll p,q;
bool judge(ll n,ll m){
	if(n*n+m*m==1)return 0;
	if(p==m&&q==n)return 0;
	if(p==-m&&q==-n)return 0;
	if(p==-n&&q==m)return 0;
	if(p==n&&q==-m)return 0;
	return (m*p+n*q)%(m*m+n*n)==0&&(m*q-n*p)%(m*m+n*n)==0;
}
void solve(){
	cin>>p>>q;
	ll val=p*p+q*q;
	bool ans=0;
	for(ll d=1;d<=val;d++)if(val%d==0){
		for(int n=0;n*n<=d;n++){
			int m=(int)sqrt(d-n*n);
			rep(f,2){
				rep(g,2){
					ans|=judge(n,m);
					m*=-1;
				}
				n*=-1;
			}
		}
	}
	cout<<(ans?"C":"P")<<endl;

}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	ll q;
	cin>>q;
	while(q--)solve();
}
accuracy: 1
time_ms: 10
memory_kb: 3368
final_rank: 9

code_snippet: #include <iostream>
#include <algorithm>
using namespace std;

void solver(int m, int n){
    for(int x = -200; x <= 200; x++){
        for(int y = -200; y <= 200; y++){
            if(min(x, y) == 0 && max(x, y) == 1) continue;
            if(min(x, y) == -1 && max(x, y) == 0) continue;
            if(x == m && y == n) continue;
            if(x == -n && y == m) continue;
            if(x == -m && y == -n) continue;
            if(x == n && y == -m) continue;
            int tot = x*x + y*y;
            if(tot > 0){
                if((m*x+n*y)%tot == 0 && (x*n-y*m)%tot == 0){
                    // cout << x << " " << y << " ";
                    cout << "C" << '\n';
                    return;
                }
            }
        }
    }
    cout << "P" << '\n';
}

int main(){
    int t;
    cin >> t;
    while(t--){
        int m, n;
        cin >> m >> n;
        solver(m, n);
    }
}
accuracy: 1
time_ms: 50
memory_kb: 3260
final_rank: 7

code_snippet: #include <stdio.h>
#include <stdlib.h>
#include <set>
using namespace std;

int gn[65536][2];
set<pair<int, int>> sieve;

int cmp1(const void* a, const void* b) {
    int ai = *(int*)a;
    int bi = *(int*)b;
    int aj = *((int*)a + 1);
    int bj = *((int*)b + 1);
    return ai * ai + aj * aj > bi * bi + bj * bj ? 1 : ai * ai + aj * aj == bi * bi + bj * bj ? 0 : -1;
}

int main(void) {
    int cnt = 0, t, x, y;
    for (int i = -200; i <= 200; i++) {
        for (int j = -200; j <= 200; j++) {
            if (i * i + j * j < 20000) {
                gn[cnt][0] = i;
                gn[cnt++][1] = j;
            }
        }
    }
    qsort(gn, cnt, sizeof(int) * 2, cmp1);
    for (int i = 5; i < cnt; i++) {
        if (sieve.find(pair<int, int>(gn[i][0], gn[i][1])) != sieve.end()) continue;
        for (int j = 5; j < cnt; j++) {
            x = gn[i][0] * gn[j][0] - gn[i][1] * gn[j][1];
            y = gn[i][0] * gn[j][1] + gn[i][1] * gn[j][0];
            if (x * x + y * y > 20000) break;
            sieve.insert(pair<int, int>(x, y));
        }
    }
    //freopen("E:\\PS\\ICPC\\Asia Pacific\\Japan Regional\\2012\\InputsAndOutputs12\\A.in", "r", stdin);
    //freopen("E:\\PS\\ICPC\\Asia Pacific\\Japan Regional\\2012\\InputsAndOutputs12\\A_t.out", "w", stdout);
    scanf("%d", &t);
    for (int tt = 0; tt < t; tt++) {
        scanf("%d %d", &x, &y);
        if (sieve.find(pair<int, int>(x, y)) != sieve.end()) printf("C\n");
        else printf("P\n");
    }
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 5924
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)


vll dx = { 1,-1,0 };
vll dy = { 1,-1,0 };
int main() {
    ll N;
    cin>>N;
    rep(n,N){
        ll M,N;
        cin>>M>>N;
        ll D=M*M+N*N;
        ll k=0;
        for(ll x=-D;x<=D;x++){
            ll B=D-x*x;
            B=sqrt(B)+1;
            for(ll y=-B;y<=B;y++){
                if(x+y==0)continue;
                ll C=x*x+y*y;
                if((M*x+N*y)%C==0&&(M*y-N*x)%C==0){
                    k++;
                   //cout<<x<<" "<<y<<endl;
                }
            }
        }
        cout<<(k==8?"P":"C")<<endl;
    }
}
accuracy: 1
time_ms: 80
memory_kb: 3208
final_rank: 6

code_snippet: #pragma region Macros
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define FOR(i, a, b) for(int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

void Case(int i) { cout << "Case #" << i << ": "; }
int popcount(int x) { return __builtin_popcount(x); }
ll popcount(ll x) { return __builtin_popcountll(x); }
#pragma endregion Macros

using P = pair<ll, ll>;
const int MAX = 20000;

void solve() {
    ll m, n;
    cin >> m >> n;
    vector<P> kouho;
    for(ll a = 0; a <= MAX and a * a <= m * m + n * n; a++) {
        for(ll b = 0; b <= MAX and a * a + b * b <= m * m + n * n; b++) {
            if((a * a + b * b) == 0) continue;
            if((m * m + n * n) % (a * a + b * b) == 0) {
                kouho.emplace_back(a, b);
                kouho.emplace_back(-a, b);
                kouho.emplace_back(a, -b);
                kouho.emplace_back(-a, -b);
            }
        }
    }
    sort(ALL(kouho));
    kouho.erase(unique(ALL(kouho)), kouho.end());
    // debug(m, n);
    // debug(kouho);
    int sz = kouho.size();
    ll ans = 0;
    REP(i, sz) {
        auto [a1, b1] = kouho[i];
        if((a1*m + b1*n) % (a1*a1+b1*b1) != 0 or (a1*n - b1*m) % (a1*a1+b1*b1) != 0) continue;
        bool ok = false;
        REP(j, sz) {
            auto [a2, b2] = kouho[j];
            if((a1 * a1 + b1 * b1) * (a2 * a2 + b2 * b2) == (m * m + n * n)) {
                ok = true;
                break;
            }
        }
        // if(ok) debug(a1, b1);
        ans += ok;
    }
    // debug(ans);
    assert(ans >= 8);
    cout << (ans == 8 ? "P" : "C") << "\n";
}

int main() {
    int T;
    cin >> T;
    while(T--) solve();
}
accuracy: 1
time_ms: 10
memory_kb: 3484
final_rank: 13

code_snippet: #ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
 
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
 
#pragma region Macros
// rep macro
#define foa(v, a) for(auto &v : a)
#define REPname(a, b, c, d, e, ...) e
#define REP(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int i = 0; i < (x); ++i)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))
#define REPSname(a, b, c, ...) c
#define REPS(...) REPSname(__VA_ARGS__, REPS1, REPS0)(__VA_ARGS__)
#define REPS0(x) for(int i = 1; i <= (x); ++i)
#define REPS1(i, x) for(int i = 1; i <= (x); ++i)
#define RREPname(a, b, c, d, e, ...) e
#define RREP(...) RREPname(__VA_ARGS__, RREP3, RREP2, RREP1, RREP0)(__VA_ARGS__)
#define RREP0(x) for(int i = (x)-1; i >= 0; --i)
#define RREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define RREP2(i, l, r) for(int i = (r)-1; i >= (l); --i)
#define RREP3(i, l, r, c) for(int i = (r)-1; i >= (l); i -= (c))
#define RREPSname(a, b, c, ...) c
#define RREPS(...) RREPSname(__VA_ARGS__, RREPS1, RREPS0)(__VA_ARGS__)
#define RREPS0(x) for(int i = (x); i >= 1; --i)
#define RREPS1(i, x) for(int i = (x); i >= 1; --i)
 
// name macro
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define popcnt(x) __builtin_popcountll(x)
template <class T = int>
using V = std::vector<T>;
template <class T = int>
using VV = std::vector<std::vector<T>>;
template <class T = int>
using VVV = std::vector<std::vector<std::vector<T>>>;
template <class T>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
using ll = long long;
using ld = long double;
using int128 = __int128_t;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using Tp = tuple<ll,ll,ll>;
 
// input macro
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
	for(T &i : v) is >> i;
	return is;
}
std::istream &operator>>(std::istream &is, __int128_t &a) {
	std::string s;
	is >> s;
	__int128_t ret = 0;
	for(int i = 0; i < s.length(); i++)
		if('0' <= s[i] and s[i] <= '9')
			ret = 10 * ret + s[i] - '0';
	a = ret * (s[0] == '-' ? -1 : 1);
	return is;
}
namespace scanner {
void scan(int &a) { std::cin >> a; }
void scan(long long &a) { std::cin >> a; }
void scan(std::string &a) { std::cin >> a; }
void scan(char &a) { std::cin >> a; }
void scan(char a[]) { std::scanf("%s", a); }
void scan(double &a) { std::cin >> a; }
void scan(long double &a) { std::cin >> a; }
template <class T, class U>
void scan(std::pair<T, U> &p) { std::cin >> p; }
template <class T>
void scan(std::vector<T> &a) { std::cin >> a; }
void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner
#define VEC(type, name, size)     \
	std::vector<type> name(size); \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                                    \
	std::vector<std::vector<type>> name(h, std::vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)             \
	std::string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHAR(...)     \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DOUBLE(...)     \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
 
// output-macro
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &a) {
	for(int i = 0; i < int(a.size()); ++i) {
		if(i) os << " ";
		os << a[i];
	}
	return os;
}
std::ostream &operator<<(std::ostream &dest, __int128_t &value) {
	std::ostream::sentry s(dest);
	if(s) {
		__uint128_t tmp = value < 0 ? -value : value;
		char buffer[128];
		char *d = std::end(buffer);
		do {
			--d;
			*d = "0123456789"[tmp % 10];
			tmp /= 10;
		} while(tmp != 0);
		if(value < 0) {
			--d;
			*d = '-';
		}
		int len = std::end(buffer) - d;
		if(dest.rdbuf()->sputn(d, len) != len) {
			dest.setstate(std::ios_base::badbit);
		}
	}
	return dest;
}
template <class T>
void print(const T a) { std::cout << a << '\n'; }
template <class Head, class... Tail>
void print(Head H, Tail... T) {
	std::cout << H << ' ';
	print(T...);
}
template <class T>
void printel(const T a) { std::cout << a << '\n'; }
template <class T>
void printel(const std::vector<T> &a) {
	for(const auto &v : a)
		std::cout << v << '\n';
}
template <class Head, class... Tail>
void printel(Head H, Tail... T) {
	std::cout << H << '\n';
	printel(T...);
}
void Yes(const bool b = true) { std::cout << (b ? "Yes\n" : "No\n"); }
void No() { std::cout << "No\n"; }
void YES(const bool b = true) { std::cout << (b ? "YES\n" : "NO\n"); }
void NO() { std::cout << "No\n"; }
void err(const bool b = true) {
	if(b) {
		std::cout << "-1\n", exit(0);
	}
}
 
//debug macro
namespace debugger {
template <class T>
void view(const std::vector<T> &a) {
	std::cerr << "{ ";
	for(const auto &v : a) {
		std::cerr << v << ", ";
	}
	std::cerr << "\b\b }";
}
template <class T>
void view(const std::vector<std::vector<T>> &a) {
	std::cerr << "{\n";
	for(const auto &v : a) {
		std::cerr << "\t";
		view(v);
		std::cerr << "\n";
	}
	std::cerr << "}";
}
template <class T, class U>
void view(const std::vector<std::pair<T, U>> &a) {
	std::cerr << "{\n";
	for(const auto &p : a) std::cerr << "\t(" << p.first << ", " << p.second << ")\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::map<T, U> &m) {
	std::cerr << "{\n";
	for(const auto &p : m) std::cerr << "\t[" << p.first << "] : " << p.second << "\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::pair<T, U> &p) { std::cerr << "(" << p.first << ", " << p.second << ")"; }
template <class T>
void view(const std::set<T> &s) {
	std::cerr << "{ ";
	for(auto &v : s) {
		view(v);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}
 
template <class T>
void view(const T &e) { std::cerr << e; }
}  // namespace debugger
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	debugger::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "\b\b]\n";                                   \
	} while(false)
#else
#define debug(...) (void(0))
#endif
 
// vector macro
template <class T>
int lb(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::lower_bound((a).begin(), (a).end(), (x))); }
template <class T>
int ub(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::upper_bound((a).begin(), (a).end(), (x))); }
template <class T>
void UNIQUE(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<T> press(std::vector<T> &a) {
	auto res = a;
	UNIQUE(res);
	for(auto &v : a)
		v = lb(res, v);
	return res;
}
#define SORTname(a, b, c, ...) c
#define SORT(...) SORTname(__VA_ARGS__, SORT1, SORT0, ...)(__VA_ARGS__)
#define SORT0(a) std::sort((a).begin(), (a).end())
#define SORT1(a, c) std::sort((a).begin(), (a).end(), [](const auto x, const auto y) { return x c y; })
template <class T>
void ADD(std::vector<T> &a, const T x) {
	for(auto &v : a) v += x;
}
template <class T>
void SUB(std::vector<T> &a, const T x = 1) {
	for(auto &v : a) v -= x;
}
template <class T>
void MUL(std::vector<T> &a, const T x) {
	for(auto &v : a) v *= x;
}
template <class T>
void DIV(std::vector<T> &a, const T x) {
	for(auto &v : a) v /= x;
}
 
// math macro
template <class T, class U>
inline bool chmin(T &a, const U &b) { return a > b ? a = b, true : false; }
template <class T, class U>
inline bool chmax(T &a, const U &b) { return a < b ? a = b, true : false; }
template <class T>
T divup(T x, T y) { return (x + y - 1) / y; }
template <class T>
T POW(T a, long long n) {
	T ret = 1;
	while(n) {
		if(n & 1) ret *= a;
		a *= a;
		n >>= 1;
	}
	return ret;
}

template<typename T>
T ADD(T a, T b){
	T res;
	return __builtin_add_overflow(a, b, &res) ? numeric_limits<T>::max() : res;
}

template<typename T>
T MUL(T a, T b){
	T res;
	return __builtin_mul_overflow(a, b, &res) ? numeric_limits<T>::max() : res;
}

// modpow
long long POW(long long a, long long n, const int mod) {
	long long ret = 1;
	while(n) {
		if(n & 1) (ret *= a) %= mod;
		(a *= a) %= mod;
		n >>= 1;
	}
	return ret;
}
 
// others
struct fast_io {
	fast_io() {
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		cout << fixed << setprecision(15);
	}
} fast_io_;

#pragma endregion

using R = long double;
constexpr R EPS=1E-11;

// r の(誤差付きの)符号に従って, -1, 0, 1 を返す.
int sgn(const R& r){ return (r > EPS) - (r < -EPS); }
// a, b の(誤差付きの)大小比較の結果に従って, -1, 0, 1 を返す.
int sgn(const R& a, const R &b){ return sgn(a-b); }
// a > 0 は sgn(a) > 0
// a < b は sgn(a, b) < 0
// a >= b は sgn(a, b) >= 0
// のように書く.
// return s * 10^n

//https://atcoder.jp/contests/abc191/submissions/20028529
long long x10(const string& s, size_t n) {
    if (s.front() == '-') return -x10(s.substr(1), n);
    auto pos = s.find('.');
    if (pos == string::npos) return stoll(s + string(n, '0'));
    return stoll(s.substr(0, pos) + s.substr(pos + 1) + string(n + pos + 1 - s.size(), '0'));
}
 
long long ceildiv(long long a, long long b) {
    if (b < 0) a = -a, b = -b;
    if (a >= 0) return (a + b - 1) / b;
    else return a / b;
}
 
long long floordiv(long long a, long long b) {
    if (b < 0) a = -a, b = -b;
    if (a >= 0) return a / b;
    else return (a - b + 1) / b;
}
 
long long floorsqrt(long long x) {
    assert(x >= 0);
    long long ok = 0;
    long long ng = 1;
    while (ng * ng <= x) ng <<= 1;
    while (ng - ok > 1) {
        long long mid = (ng + ok) >> 1;
        if (mid * mid <= x) ok = mid;
        else ng = mid;
    }
    return ok;
}

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){//popcount%2
	return __builtin_parity(x);
}

const int inf = 1e9;
const ll INF = 1e18;



void main_() {
	int q;
	cin >> q;
	REP(i,q){
	    int p,q;
	    cin >> p >> q;
	    bool ex = false;
	    for(int i = -200;i <= 200;i++){
	        for(int j = -200;j <= 200;j++){
	            if(i == 0 && j == 0)continue;
	            int n = q * i - p * j;
	            int m = p * i + q * j;
	            int sum = i * i + j * j;
	            if(sum == 1 || sum == p * p + q * q)continue;
	            if(n % sum == 0 && m % sum == 0){
	                ex = true;
	            }
	        }
	    }
	    if(ex)cout << 'C' << endl;
	    else cout << 'P' << endl;
	}
}
 
int main() {
	int t = 1;
	//cin >> t;
	while(t--) main_();
	return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3396
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

bool D(int a,int b){
  a=abs(a);b=abs(b);
  return (a%b)==0;
}

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

bool pr(int p,int q){
  for(int m=-200;m<=200;m++)for(int n=-200;n<=200;n++){
    if(m==0&&n==0)continue;
    bool out=false;
    REP(i,4)if(dx[i]==m&&dy[i]==n)out=true;
    if(m==p&&n==q)out=true;
    if(m==-q&&n==p)out=true;
    if(m==-p&&n==-q)out=true;
    if(m==q&&n==-p)out=true;
    if(out)continue;
    if(D(m*p+n*q,m*m+n*n)&&D(m*q-n*p,m*m+n*n))return false;
  }
  return true;
}

int main(){
  int x;cin>>x;
  while(x--){
    int p,q;cin>>p>>q;
    if(p*p+q*q==0)cout<<"C"<<endl;
    else if(pr(p,q))cout<<"P"<<endl;
    else cout<<"C"<<endl;
  }
}
accuracy: 1
time_ms: 80
memory_kb: 3268
final_rank: 10

code_snippet: #include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip> 
#include <stdio.h>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define pii pair <int,int>
#define rep(i,n) for(int i = 0 ; i < n ; i++) 
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define vi vector <int> 
#define vec(...) vector<__VA_ARGS__>
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
//eodefine
using namespace std;

const int max_n = 103002;

void slv(int p,int q) {
	int ans=0;
	for(int x=-200;x<=200;x++){
		for(int y=-200;y<=200;y++) {
			if(x==0 and y==0)continue;
			int n = (q*x-p*y)/(y*y+x*x);
			int m = (q*y+p*x)/(y*y+x*x);
			if(m*x-n*y==p and m*y+n*x==q) ans++;
			// ans++;
		}
	}
	if(ans==8)cout<<"P\n";
	else cout<<"C\n";
	// cout<<ans<<"\n";
}

int main(){
fcin;
	int t;
	cin>>t;
	while(t--) {
		int n,m;
		cin>>n>>m;
		slv(n,m);
	}
/*
*/
    return 0;   
}
accuracy: 1
time_ms: 130
memory_kb: 3312
final_rank: 16

code_snippet: #include <bits/stdc++.h>

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//using namespace boost::multiprecision;
//#include<atcoder/all>
//#include<atcoder/segtree>
//#include <atcoder/scc>
//using namespace atcoder;

using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

ll mod = 998244353ll;
//ll mod = 1000000007ll;
//const ll mod = 4;


struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime modhttps://atcoder.jp/contests/abc166/submit?taskScreenName=abc166_f
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

#define rep(i, n)         for(ll i = 0; i < (ll)(n); i++)
//#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define bbrep(n)           for(int bbit=0;bbit<(1<<n);bbit++)
#define erep(i,container) for (auto &i : container)
#define itrep(i,container) for (auto i : container)
#define irep(i, n)        for(ll i = n-1; i >= (ll)0ll; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define repreprep(i,j,k,h,w,n) rep(i,h)rep(j,w)rep(k,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
//#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define kout(d) std::cout << keta(10)<< d<< std::endl;
#define vout(a) erep(qxqxqx,a)std::cout << qxqxqx << ' ';std::cout  << std::endl;
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
//#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
//#define case std::cout <<"Case #" <<qqq+1<<":"
#define RES(a,iq,jq) a.resize(iq);rep(iii,iq)a[iii].resize(jq);

#define RESRES(a,i,j,k) a.resize(i);rep(ii,i)a[ii].resize(j);reprep(ii,jj,i,j){a[ii][jj].resize(k);};
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define ppppri(a,b,c,d) std::cout << a<<" "<<b <<" "<< c<<' '<<d<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define SUMI(a) accumulate(all(a),0) 
#define SUM(a) accumulate(all(a),0ll) 
#define stirng string
#define gin(a,b) int a,b;std::cin >> a>>b;a--;b--;
#define popcount __builtin_popcount
#define permu(a) next_permutation(all(a))
#define aru(a,d) a.find(d)!=a.end()
#define nai(a,d) a.find(d)==a.end()
//#define aru p.find(mp(x,y))!=p.end()
//#define grid_input(a,type) int h,w;std::cin >> h>>w;vvector(a,type,h,w,0);reprep(i,j,h,w)std::cin >> a[i][j];

//typedef long long T;
ll ceili(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 2000000000;
//const ll INF64 =922330720854775807ll;
const ll INF64 = 4223372036854775807ll;
//const ll INF64 = 9223372036854775807ll;

//const ll INF64 = 243'000'000'000'000'000'0;Q


//const ll MOD = 1000000007ll;
const ll MOD = 998244353ll;
//const ll MOD = 1000003ll;
const ll OD = 1000000000000007ll;
const dou pi=3.141592653589793;

long long modpow(long long a, long long n) { 
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}
vector< ll > divisor(ll n) {  //約数の列挙
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//メモ
//ゲーム(Grundy数とか)の復習をする
//リスニング力をどうにかする
//個数制限付きナップサックの復習
//戻すDP
//全方位木DPとスライド最小値
//ゲーム→パリティに注目するといいことあるかも
//ゲーム→もとの状態に戻せる状態を探す
//理由がなければLLを使え！
//理由がなければLLを使え！
//理由がなければLLを使え！
//理由がなければLLを使え！
//理由がなければLLを使え！
//理由がなければLLを使え！
//理由がなければLLを使え！
//理由がなければLLを使え！
//来週の月曜日に銀行へ行く
//積率を調べる実験を来週の火曜日までにやる
//レピュニット数
//フェルマーの小定理
//拡張ユークリッド

int main(){
    std::set<int> st;
    rrep(i,0,12000){
        st.insert(i*i);
    }
    query{
        ll p,q;
        std::cin >> p>>q;
        int v=p*p+q*q;
        auto di=divisor(p*p+q*q);
        std::vector<bool> ok(di.size());
        int po=0;
        char c='P';
        erep(ii,di){
            if(ii==1||ii==p*p+q*q){
                1==1;
            }
            else{
                bool ook=0;
                erep(i,st){
                    if(aru(st,ii-i))ook=1;
                }
                ok[po]=ook;
            }
            //rep(i,ok.size())std::cout << ok[i] << ' ';
            //std::cout << std::endl;
           // ppri(po,ok.size()-1-po);
            if(ok[po]&ok[ok.size()-1-po])c='C';
            po++;
        }
        std::cout << c << std::endl;
    }
}
accuracy: 1
time_ms: 340
memory_kb: 3608
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define int long long

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif

#define MAX_N (1000006)
#define INF (1LL << 60)
#define eps 1e-9
const int MOD = (int)1e9 + 7;


signed main(){
    //cin.tie(nullptr);
    //std::ios::sync_with_stdio(false);

    int t;
    cin >> t;

    while(t--){
        int m,n;
        cin >> m >> n;

        int cnt = 0;
        int mx = abs(max(abs(m),abs(n)));
        for(int p=-mx; p<=mx; p++){
            for(int q=-mx; q<=mx; q++){
                int d = p*p + q*q;
                if(d==0) continue;
                int d1 = p*m + q*n;
                int d2 = p*n - q*m;
                if(d1%d==0 && d2%d==0) {
                    debug(p,q);
                    cnt++;
                }
            }
        }
        debug(cnt);
        cout << (cnt==8?"P":"C") << endl;
    }
}

/*


*/
accuracy: 1
time_ms: 40
memory_kb: 3072
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

void solve() {
    int p, q;
    cin >> p >> q;
    int cnt = 0;
    for (int m = -200; m <= 200; ++m) {
        for (int n = -200; n <= 200; ++n) {
            if (m == n && n == 0) continue;
            int x = m*m + n*n;
            int y = m*p + n*q;
            int z = m*q - n*p;
            if (y % x == 0 && z % x == 0) cnt++;
        }
    }
    cout << (cnt == 8 ? 'P' : 'C') << '\n';
}

int main() {
    int t;
    cin >> t;
    while (t--) solve();
}
accuracy: 1
time_ms: 80
memory_kb: 3332
final_rank: 12

code_snippet: #pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double eps = 1e-9;
// constexpr ll mod = 1000000007;
constexpr ll mod = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// --------------------------------------------------------------------------




int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int _;
  cin >> _;
  while(_--){
    int m,n;
    cin >> m >> n;
    int cnt = 0;
    for(int i=-1000; i<1000; i++){
      for(int j=-1000; j<1000; j++){
        // if(i*i+j*j > m*m+n*n) break;
        if(i*i+j*j < 1) continue;
        if((i*m+j*n)%(i*i+j*j)==0 && (i*n-j*m)%(i*i+j*j)==0) cnt++;
      }
    }
    if(cnt == 8){
      cout << "P\n";
    }else{
      cout << "C\n";
    }
  }
  return 0;
}
accuracy: 1
time_ms: 1800
memory_kb: 3356
final_rank: 19

code_snippet: #pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double eps = 1e-9;
// constexpr ll mod = 1000000007;
constexpr ll mod = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// --------------------------------------------------------------------------




int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int _;
  cin >> _;
  while(_--){
    int m,n;
    cin >> m >> n;
    int cnt = 0;
    for(int i=-1000; i<1000; i++){
      for(int j=-1000; j<1000; j++){
        // if(i*i+j*j > m*m+n*n) break;
        if(i*i+j*j <= 1) continue;
        if((i*m+j*n)%(i*i+j*j)==0 && (i*n-j*m)%(i*i+j*j)==0) cnt++;
      }
    }
    if(cnt == 4){
      cout << "P\n";
    }else{
      cout << "C\n";
    }
  }
  return 0;
}
accuracy: 1
time_ms: 1800
memory_kb: 3380
final_rank: 20

code_snippet: #include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

void solve(){
	int p,q; cin >> p >> q;
	int r = p*p + q*q;
	int cnt = 0;
	for(int m=-150; m<=150; m++){
		for(int n=-150; n<=150; n++){
			if(m==0 && n==0) continue;
			int s = m*m + n*n;
			if(r % s != 0) continue;
			int t = r / s;
			bool f = false;
			for(int x=0; x<=150; x++){
				int Y = t - x*x;
				int y = sqrt(Y);
				if(y*y != Y) continue;
				f = true; break;
			}
			if((m*p + n*q) % s == 0 && (m*q - n*p) % s == 0) cnt++;
		}
	}
	if(cnt == 8) puts("P");
	else puts("C");
}

int main(){
	int t; cin >> t;
	while(t--){
		solve();
	}
}
accuracy: 1
time_ms: 50
memory_kb: 3092
final_rank: 3

code_snippet: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> T;
	while (T--) {
		cin >> N >> M;
		int ans = 0;
		for (int i = -150; i <= 150; i++) {
			for (int j = -150; j <= 150; j++) {
				if (!i && !j)continue;
				if ((i*N + j * M) % (i*i + j * j) == 0 && (i*M - j * N) % (i*i + j * j) == 0)ans++;
			}
		}
		if (ans == 8)cout << "P" << endl;
		else cout << "C" << endl;
	}
}
accuracy: 1
time_ms: 130
memory_kb: 3044
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    int m, n;
    cin >> m >> n;
    int s = m * m + n * n;
    bool prime = true;
    int a = sqrt(s - 1);
    for (int j = - a; j <= a; j++){
      int b = sqrt(s - j * j - 1);
      for (int k = - b; k <= b; k++){
        int t = j * j + k * k;
        if (abs(t) > 1){
          if ((j * m + k * n) % (j * j + k * k) == 0 && (j * n - k * m) % (j * j + k * k) == 0){
            prime = false;
          }
        }
      }
    }
    if (prime){
      cout << 'P' << endl;
    } else {
      cout << 'C' << endl;
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 2988
final_rank: 1