#P5656. 【模板】二元一次不定方程 (exgcd)
【模板】二元一次不定方程 (exgcd)
Problem Description
Given the indeterminate equation
If this equation has no integer solution, output .
If this equation has integer solutions and also has positive integer solutions, output: the number of positive integer solutions, the minimum value of among all positive integer solutions, the minimum value of among all positive integer solutions, the maximum value of among all positive integer solutions, and the maximum value of among all positive integer solutions.
If the equation has integer solutions but has no positive integer solution, you need to output: the minimum positive integer value of among all integer solutions, and the minimum positive integer value of among all integer solutions.
A positive integer solution means a solution where both and are positive integers, and is not a positive integer.
An integer solution means a solution where both and are integers.
The minimum positive integer value of means the minimum value of among all integer solutions with being a positive integer, and similarly for .
Input Format
The first line contains a positive integer , representing the number of test cases.
The next lines each contain three positive integers separated by spaces.
Output Format
Output lines.
If the corresponding query has no integer solution, output a single number .
If the corresponding query has integer solutions but no positive integer solution, output numbers separated by spaces, representing the minimum positive integer value of and the minimum positive integer value of among integer solutions, in order.
Otherwise, output numbers separated by spaces, representing the number of positive integer solutions, the minimum , the minimum , the maximum , and the maximum among positive integer solutions, in order.
The input and output sizes are large, so please use fast I/O methods.
7
2 11 100
3 18 6
192 608 17
19 2 60817
11 45 14
19 19 810
98 76 5432
4 6 2 39 8
2 1
-1
1600 1 18 3199 30399
34 3
-1
2 12 7 50 56
Hint
Constraints
For of the testdata, , .
Translated by ChatGPT 5