luogu#P4980. 【模板】Pólya 定理
【模板】Pólya 定理
Problem Description
Given a cycle with vertices and edges, there are colors. Color each vertex, and ask how many essentially different coloring schemes there are. Output the answer modulo .
Note that in this problem, “essentially different” is defined as: it only needs to be different up to rotation, i.e., two colorings are considered the same if one can be obtained from the other by rotation.
Input Format
The first line contains an integer , meaning there are test cases.
Starting from the second line, there are lines in total. Each line contains an integer , with the meaning as described above.
Output Format
There are lines in total. Each line contains one number, representing the number of coloring schemes modulo .
5
1
2
3
4
5
1
3
11
70
629
Hint
Translated by ChatGPT 5