#P6736. 「Wdsr-2」白泽教育

    ID: 5707 远端评测题 1000~2000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2020递归数论洛谷原创O2优化枚举,暴力欧拉公式块状链表,块状数组,分块

「Wdsr-2」白泽教育

Input Format

This problem contains multiple test cases.

The first line contains an integer TT, the number of test cases.

For each test case:

One line contains four integers a,n,b,pa, n, b, p.

Output Format

For each test case, output one line with one integer. If the original equation has a solution, output the smallest non-negative integer solution; otherwise, output 1-1.

3
2 1 1 3
3 1 2 7
7 1 2 4
0
2
-1
3
2 2 4 7
3 2 4 6
5 2 1 3
2
-1
0
3
4 3 5 8
2 3 9 11
6 3 1 5
-1
3
0

Hint

This problem uses bundled evaluation.

Subtask nn pp TT Score Time Limit
11 n=1n = 1 2p1092 \leq p \leq 10^9 and pp is prime 1T1001 \leq T \leq 100 15pts15 \operatorname{pts} 2.00s2.00 \operatorname{s}
22 n=2n = 2 No special constraints 1T5×1031 \leq T \leq 5 \times 10^3 25pts25 \operatorname{pts} 1.00s1.00 \operatorname{s}
33 n=3n = 3 No special constraints 60pts60 \operatorname{pts} 2.00s2.00 \operatorname{s}

For 100%100\% of the testdata, 1a1091 \leq a \leq 10^9, 1n31 \leq n \leq 3, 0b<p1090 \leq b < p \leq 10^9, 1T2×1041 \leq T \leq 2 \times 10^4.

Translated by ChatGPT 5