問題一覧 > 通常問題

No.1579 New Type of Nim

レベル : / AI推定難易度 : 1200 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 143
作問者 : magsta / テスター : startcpp
お気に入りにしたユーザー ProblemId : 6208 / 自分の提出
問題文最終更新日: 2021-07-03 00:23:31
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 302 (順位表) の他の問題:

Problem Statement

P and Q play a stone-taking game. Initially there are 2 piles: the first pile contains $A$ stones and the second pile contains $B$ stones.

As long as there is a pile with stones remaining, P and Q repeat the following operation. Initially, the player to operate is P. After an operation, if the numbers of stones in the 2 piles are not equal, the player to operate switches.

  • Choose 1 pile with stones remaining, and remove any number (at least 1) of stones from that pile.

When neither of the 2 piles has any stones left, the player who took the last stone wins. Determine which player wins when both play optimally.

Print P if P wins, and Q if Q wins.

Input

$A\ \ B$

  • $1 \leq A, B \leq 10^9$
  • All inputs are integers

Output

Print P or Q, followed by a newline.

Sample

Sample 1
Input
1 2
Output
Q

If P chooses the first pile, 1 pile with 2 stones remains, and Q can win by taking the 2 stones.

If P chooses the second pile and takes 2 stones, 1 pile with 1 stone remains, and Q can win by taking the 1 stone.

If P chooses the second pile and takes 1 stone, 2 piles with 1 stone each remain, so the player to operate does not switch and remains P.
Whatever operation P performs from here, 1 pile with 1 stone remains, and Q can win by taking the 1 stone.

Therefore, Q can win no matter how P operates from the start.

Sample 2
Input
4 3
Output
Q

Sample 3
Input
12398742 83717408
Output
P

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。