orz PoPoQQQ神犇,每一篇题解都写得很清楚
(看了PoPoQQQ的哲♂学三部曲,瑟瑟发抖)
CODE
#include <cstdio>
#include <algorithm>
using namespace std;
#define stop(x) return puts(x), 0
inline void read(int &num) {
char ch; while((ch=getchar())<'0'||ch>'9');
for(num=0;ch>='0'&&ch<='9';num=num*10+ch-'0',ch=getchar());
}
bool chk(int p, int q, int n) {
return (n % p < q) && (n % p % (p-q) == 0);
}
int p, q, n, T;
inline int solve () {
read(p), read(q), read(n);
int tmp = __gcd(p, q);
if(n % tmp) stop("R");
if(p == q) stop("E");
p/=tmp, q/=tmp, n/=tmp;
if(p > q) {
if(n < p) stop("P");
else stop(chk(p, q, n) ? "E" : "P");
}
else {
if(n < p) {
if(n+p < q) stop("E");
else stop(chk(q, p, n+p) ? "P" : "E");
}
else stop("E");
}
}
int main () {
read(T);
while(T--) solve();
}