#P6091. 【模板】原根
【模板】原根
Description
Given an integer , find all of its primitive roots.
To reduce the amount of output, an output parameter is given. Suppose has primitive roots, and in increasing order they are . You only need to output $g_d,g_{2d},\ldots,g_{\lfloor\frac{c}{d}\rfloor\times d}$ in order.
If you do not know the definition of a primitive root, you may look it up yourself or read the definition below:
A positive integer is a primitive root of a positive integer if and only if , and the multiplicative order of modulo is .
Input Format
This problem contains multiple test cases.
The first line: an integer , the number of test cases.
The next lines: each line contains two integers , representing one query.
Output Format
For each test case:
Output an integer in the first line, which is the number of primitive roots of . In the second line, output numbers as required in the statement.
Note: even if , you still need to output an empty line.
6
2 1
4 1
25 2
36 1
9 6
18 1
1
1
1
3
8
3 12 17 23
0
2
2
5 11
Hint
[Sample Explanation]
For test cases , all primitive roots of the given appear in the output.
For test case , the set of primitive roots of is .
For test case , the set of primitive roots of is .
[Constraints]
For of the testdata, , , . It is guaranteed that the total number of output integers does not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号