#nt103. 扩展欧几里得2
扩展欧几里得2
Extended Euclidean 2
Problem Description
Read ; there are groups of data. Each group gives three numbers ; output a non-negative integer solution of . If there is no solution, output ; otherwise output the solution with the smallest .
Input Format
The first line contains one number .
The following lines each contain three numbers .
Output Format
lines in total, each with two numbers: .
Sample Input
3
1 2 5
100 150 1000
3 2 1
Sample Output
1 2
1 6
-1
Constraints
For of the data, it is guaranteed that , , .
Hint
- Use the extended Euclidean algorithm to solve . A solution to exists iff . To get the smallest non-negative , first find one solution then shift by multiples of (and for ).