luogu#P4980. 【模板】Pólya 定理

【模板】Pólya 定理

Problem Description

Given a cycle with nn vertices and nn edges, there are nn colors. Color each vertex, and ask how many essentially different coloring schemes there are. Output the answer modulo 109+710^9+7.

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 tt, meaning there are tt test cases.

Starting from the second line, there are tt lines in total. Each line contains an integer nn, with the meaning as described above.

Output Format

There are tt lines in total. Each line contains one number, representing the number of coloring schemes modulo 109+710^9+7.

5
1 
2 
3 
4 
5 
1
3
11
70
629

Hint

n109n \leq 10^9 t103t \leq 10^3

Translated by ChatGPT 5