#P8814. [CSP-J 2022] 解密

[CSP-J 2022] 解密

Problem Description

Given a positive integer kk, there are kk queries. In each query, three positive integers ni,ei,din_i, e_i, d_i are given. Find two positive integers pi,qip_i, q_i such that ni=pi×qin_i = p_i \times q_i and ei×di=(pi1)(qi1)+1e_i \times d_i = (p_i - 1)(q_i - 1) + 1.

Input Format

The first line contains a positive integer kk, meaning there are kk queries.

The next kk lines each contain three positive integers ni,di,ein_i, d_i, e_i on the ii-th line.

Output Format

Output kk lines. Each line contains two positive integers pi,qip_i, q_i as the answer.

To make the output consistent, you should ensure that piqip_i \leq q_i.

If there is no solution, output NO.

10
770 77 5
633 1 211
545 1 499
683 3 227
858 3 257
723 37 13
572 26 11
867 17 17
829 3 263
528 4 109

2 385
NO
NO
NO
11 78
3 241
2 286
NO
NO
6 88

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=ne×d+2m = n - e \times d + 2.

It is guaranteed that for 100%100\% of the testdata, 1k1051 \leq k \leq {10}^5. For any 1ik1 \leq i \leq k, 1ni10181 \leq n_i \leq {10}^{18}, 1ei×di10181 \leq e_i \times d_i \leq {10}^{18}, and 1m1091 \leq m \leq {10}^9.

::cute-table{tuack}

Test Point ID kk \leq nn \leq mm \leq Special Property
11 10310^3 10310^3 A solution is guaranteed.
22 None.
33 10910^9 6×1046\times 10^4 A solution is guaranteed.
44 None.
55 10910^9 A solution is guaranteed.
66 None.
77 10510^5 101810^{18} If a solution exists, then p=qp = q is guaranteed.
88 A solution is guaranteed.
99 None.
1010

Translated by ChatGPT 5