P8814 [CSP-J 2022] Decryption
Description
Given a positive integer $k$, there are $k$ queries. In each query, three positive integers $n_i, e_i, d_i$ are given. Find two positive integers $p_i, q_i$ such that $n_i = p_i \times q_i$ and $e_i \times d_i = (p_i - 1)(q_i - 1) + 1$.
Input Format
The first line contains a positive integer $k$, meaning there are $k$ queries.
The next $k$ lines each contain three positive integers $n_i, d_i, e_i$ on the $i$-th line.
Output Format
Output $k$ lines. Each line contains two positive integers $p_i, q_i$ as the answer.
To make the output consistent, you should ensure that $p_i \leq q_i$.
If there is no solution, output `NO`.
Explanation/Hint
**Sample \#2**
See `decode/decode2.in` and `decode/decode2.ans` in the attachment.
**Sample \#3**
See `decode/decode3.in` and `decode/decode3.ans` in the attachment.
**Sample \#4**
See `decode/decode4.in` and `decode/decode4.ans` in the attachment.
**Constraints**
Let $m = n - e \times d + 2$.
It is guaranteed that for $100\%$ of the testdata, $1 \leq k \leq {10}^5$. For any $1 \leq i \leq k$, $1 \leq n_i \leq {10}^{18}$, $1 \leq e_i \times d_i \leq {10}^{18}$, and $1 \leq m \leq {10}^9$.
::cute-table{tuack}
| Test Point ID | $k \leq$ | $n \leq$ | $m \leq$ | Special Property |
| :----------: | :----------: | :----------: | :----------: | :----------: |
| $1$ | $10^3$ | $10^3$ | $10^3$ | A solution is guaranteed. |
| $2$ | $10^3$ | $10^3$ | $10^3$ | None. |
| $3$ | $10^3$ | $10^9$ | $6\times 10^4$ | A solution is guaranteed. |
| $4$ | $10^3$ | $10^9$ | $6\times 10^4$ | None. |
| $5$ | $10^3$ | $10^9$ | $10^9$ | A solution is guaranteed. |
| $6$ | $10^3$ | $10^9$ | $10^9$ | None. |
| $7$ | $10^5$ | $10^{18}$ | $10^9$ | If a solution exists, then $p = q$ is guaranteed. |
| $8$ | $10^5$ | $10^{18}$ | $10^9$ | A solution is guaranteed. |
| $9$ | $10^5$ | $10^{18}$ | $10^9$ | None. |
| $10$ | $10^5$ | $10^{18}$ | $10^9$ | None. |
Translated by ChatGPT 5