Equation

AtCoder
IDarc158_d
Time4000ms
Memory256MB
Difficulty
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$ [samples]
Samples
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.
API Response (JSON)
{
  "problem": {
    "name": "Equation",
    "description": {
      "content": "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$. *   $(",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 4000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc158_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a positive integer $n$, and a prime number $p$ at least $5$.\nFind a triple of integers $(x,y,z)$ that satisfies all of the following conditions.\n\n*   $1\\leq x < y < z \\leq p - 1$.\n*   $(...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments