#P5656. 【模板】二元一次不定方程 (exgcd)

    ID: 6323 远端评测题 500ms 16MiB 尝试: 2 已通过: 1 难度: 7 上传者: 标签>数学最大公约数 gcd扩展欧几里德算法

【模板】二元一次不定方程 (exgcd)

Problem Description

Given the indeterminate equation

ax+by=cax+by=c

If this equation has no integer solution, output 1-1.
If this equation has integer solutions and also has positive integer solutions, output: the number of positive integer solutions, the minimum value of xx among all positive integer solutions, the minimum value of yy among all positive integer solutions, the maximum value of xx among all positive integer solutions, and the maximum value of yy 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 xx among all integer solutions, and the minimum positive integer value of yy among all integer solutions.

A positive integer solution means a solution where both xx and yy are positive integers, and 0\boldsymbol{0} is not a positive integer.
An integer solution means a solution where both xx and yy are integers.
The minimum positive integer value of xx means the minimum value of xx among all integer solutions with xx being a positive integer, and similarly for yy.

Input Format

The first line contains a positive integer TT, representing the number of test cases.

The next TT lines each contain three positive integers a,b,ca, b, c separated by spaces.

Output Format

Output TT lines.

If the corresponding query has no integer solution, output a single number 1-1.
If the corresponding query has integer solutions but no positive integer solution, output 22 numbers separated by spaces, representing the minimum positive integer value of xx and the minimum positive integer value of yy among integer solutions, in order.
Otherwise, output 55 numbers separated by spaces, representing the number of positive integer solutions, the minimum xx, the minimum yy, the maximum xx, and the maximum yy 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 100%100\% of the testdata, 1T2×1051 \le T \le 2 \times {10}^5, 1a,b,c1091 \le a, b, c \le {10}^9.

Translated by ChatGPT 5