No.2725 Coprime Game 2
Problem Statement
You are given an integer $N$ that is at least $2$.
There is a variable $y$ initialized as $y = N$, and Koa and Pache play a game using it.
Starting with Koa, they alternately perform the following operation.
Among the integers $x$ between $2$ and $y$, inclusive, choose $1$ that satisfies all of the following conditions, and then set $y = x$.
$x$ is not a divisor of $N$
$x$ and $y$ are coprime
The player who first becomes unable to perform the operation loses.
Determine who wins when both players play optimally.
Find the answer for $T$ test cases.
Constraints
$1 \leq T \leq 10^{5}$
$2 \leq N \leq 10^{18}$
All input values are integers
Input
The input is given in the following format.
$T$
$\mathrm{case}_{1}$
$\mathrm{case}_{2}$
$\vdots$
$\mathrm{case}_{T}$
Each test case is given in the following format.
$N$
Output
Print the answers, $1$ per line, for a total of $T$ lines.
On line $i$ $(1 \leq i \leq T)$, for the game played on the $i$-th test case, print Koa wins as K, and Pache wins as P; that is, print the letter corresponding to the winner.
Sample
Sample 1
Input
5 3 18 2023 2 1000000000000000000
Output
K P K P K
First, in the $1$st test case, Koa has a winning strategy. For example, the operations proceed as follows.
Since $2 \leq 2 \leq y = 3$, $2$ and $3$ are coprime, and $2$ is not a divisor of $3$,
Koa chooses $x = 2$ and then sets $y = 2$.There is no integer $x$ that Pache can choose, so Koa wins.
Next, in the $2$nd test case, Pache has a winning strategy. For example, the operations proceed as follows.
Since $2 \leq 11 \leq y = 18$, $11$ and $18$ are coprime, and $11$ is not a divisor of $18$,
Koa chooses $x = 11$ and then sets $y = 11$.Since $2 \leq 4 \leq y = 11$, $4$ and $11$ are coprime, and $4$ is not a divisor of $18$,
Pache chooses $x = 4$ and then sets $y = 4$.There is no integer $x$ that Koa can choose, so Pache wins.
Finding the answers for the remaining test cases in the same way gives the output shown above.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
MasKoaTS