AtCoder Regular Contest 166
F
Tangent Addition Formula
AtCoder
⌀ 3692
原题
← E→
翻译中…

Problem Statement

翻译中…

You are given a prime number $p$ and non-negative integers $a$ and $b$.

翻译中…

Determine if there is an infinite sequence of non-negative integers $t = \bigl(t(0), t(1), t(2), \ldots)$ that satisfies all of the following conditions.

翻译中…
  • $0\leq t(x) < p$ for every non-negative integer $x$.
  • $t(x+y)\bigl(1-t(x)t(y)\bigr)\equiv t(x)+t(y)\pmod{p}$ for all non-negative integers $x$ and $y$.
  • $t(a)=b$.
翻译中…

You have $T$ test cases to solve.

翻译中…

Constraints

翻译中…
  • $1\leq T\leq 2\times 10^5$
  • $p$ is a prime number such that $1\leq p\leq 10^9$.
  • $0\leq a\leq 10^{9}$
  • $0\leq b < p$
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
\text{case}_1
\vdots
\text{case}_T

翻译中…

Each test case is given in the following format:

翻译中…

p a b

翻译中…

Output

翻译中…

Print $T$ lines. The $i$-th line should contain Yes if there is a sequence of non-negative integers that satisfies all of the conditions, and No otherwise.

翻译中…

样例

Input #1
4
11 1 0
11 1 1
11 1 3
11 1 5
Output #1
Yes
No
No
Yes
- For $p=11, a=1, b=0$, a constant sequence $t = (0,0,0,0,\ldots)$ satisfies the conditions. - For $p=11, a=1, b=5$, a sequence $t = (0,5,6,0,5,6,\ldots)$ of period $3$ satisfies the conditions.
Input #2
5
5 0 0
5 1 1
5 2 2
5 3 3
5 4 4
Output #2
Yes
No
Yes
Yes
No
Input #3
7
2 3 1
2 5 0
5 0 1
5 0 2
7 1 4
11 12345 5
13 12345 5
Output #3
Yes
Yes
No
Yes
No
No
Yes
题目信息
题号
arc166_f
时间限制
10 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。