AtCoder Regular Contest 172
E
Last 9 Digits
AtCoder
⌀ 2358
原题
← DF →
翻译中…

Problem Statement

翻译中…

Determine whether there is a positive integer $n$ such that the remainder of $n^n$ divided by $10^9$ is $X$. If it exists, find the smallest such $n$.

翻译中…

You will be given $Q$ test cases to solve.

翻译中…

Constraints

翻译中…
  • $1 \leq Q \leq 10000$
  • $1 \leq X \leq 10^9 - 1$
  • $X$ is neither a multiple of $2$ nor a multiple of $5$.
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format, where $X_i$ is the value of $X$ in the $i$-th test case $(1 \leq i \leq Q)$:

翻译中…

Q
X_1
X_2
\vdots
X_Q

翻译中…

Output

翻译中…

Print $Q$ lines. The $i$-th line should contain the answer for the $i$-th test case. If no $n$ satisfies the condition, the answer should be $-1$.

翻译中…

样例

Input #1
2
27
311670611
Output #1
3
11
This sample input consists of two test cases. - The first case: The remainder of $3^3 = 27$ divided by $10^9$ is $27$, so $n = 3$ satisfies the condition. - The second case: The remainder of $11^{11} = 285311670611$ divided by $10^9$ is $311670611$, so $n = 11$ satisfies the condition.
题目信息
题号
arc172_e
时间限制
2 s
内存限制
1024 MB

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