Solve modular linear equation

0

0 votes
Easy
Problem

Find all the solutions of the equation
ax ≡ b (mod n)
That is, find all possible values of x in (mod n) for a given set of values of a, b and n, where a > 0 and n > 0.

Input Format:
Input starts with the number t of test-cases. Each test case has three integers a, b and n in a single line.

Output Format:
One line per test-case. A test-case starts with a number indicating the number of solutions the equation has followed by the solutions in non-decreasing order. All numbers are separated by a space.

Constraints:
1≤ t ≤ 100
1 ≤ a ≤ 1000
0 ≤ b ≤ 1000
1 ≤ n ≤ 10^6

Sample Input
2
14 30 100
6 4 15
Sample Output
2 45 95
0
Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?