AtCoder Regular Contest 158
D
Equation
AtCoder
⌀ 2893
原题
← CE →
翻译中…

Problem Statement

翻译中…

You are given a positive integer $n$, and a prime number $p$ at least $5$.

翻译中…

Find a triple of integers $(x,y,z)$ that satisfies all of the following conditions.

翻译中…
  • $1\leq x < y < z \leq p - 1$.
  • $(x+y+z)(x^n+y^n+z^n)(x^{2n}+y^{2n}+z^{2n}) \equiv x^{3n}+y^{3n}+z^{3n}\pmod{p}$.
翻译中…

It can be proved that such a triple $(x,y,z)$ always exists.

翻译中…

You have $T$ test cases to solve.

翻译中…

Constraints

翻译中…
  • $1\leq T\leq 10^5$
  • $1\leq n\leq 10^9$
  • $p$ is a prime number satisfying $5\leq p\leq 10^9$.
翻译中…

Input

翻译中…

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

翻译中…

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

翻译中…

Each case is in the following format:

翻译中…

n p

翻译中…

Output

翻译中…

Print $T$ lines. The $i$-th line should contain $x,y,z$ with spaces in between where $(x,y,z)$ is a solution for the $i$-th test case.

翻译中…

If multiple solutions exist, you may print any of them.

翻译中…

样例

Input #1
3
1 7
2 7
10 998244353
Output #1
1 4 6
1 2 5
20380119 21549656 279594297
For the first test case: - $(x+y+z)(x^n+y^n+z^n)(x^{2n}+y^{2n}+z^{2n}) = (1+4+6)(1+4+6)(1+16+36) = 6413$, and - $x^{3n}+y^{3n}+z^{3n} = 1 + 64 + 216 = 281$. We have $6413\equiv 281\pmod{7}$, so the conditions are satisfied.
题目信息
题号
arc158_d
时间限制
4 s
内存限制
1024 MB

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