#P3993. [BJOI2017] 同构

[BJOI2017] 同构

Description

You have nn vertices. You may add undirected edges between these nn vertices, with at most one edge per pair and no self-loops. What is the maximum number of edges you can add?

The obvious answer is n(n1)2\dfrac{n(n-1)}{2} edges. Therefore, there is an additional constraint: the graph must not have a nontrivial automorphism.

A graph GG has a nontrivial automorphism if there exists a permutation pp of {1,,n}\{1, \dots, n\} such that for all vertices u,vu, v, there is an edge between uu and vv if and only if there is an edge between p(u)p(u) and p(v)p(v), and this permutation is nontrivial, i.e., there exists a vertex uu with p(u)up(u) \ne u.

For example, for the 5-vertex graph (1,2),(2,3),(3,4),(4,5),(5,1),(1,3)(1,2),(2,3),(3,4),(4,5),(5,1),(1,3), the mapping p(1)=3p(1)=3, p(2)=2p(2)=2, p(3)=1p(3)=1, p(4)=5p(4)=5, p(5)=4p(5)=4 is a nontrivial automorphism of this graph.

You need to answer: among simple undirected graphs on nn vertices that have no nontrivial automorphism, what is the maximum number of edges? If no such graph on nn vertices exists, output -1; otherwise, output the answer modulo 109+710^9+7.

Input Format

This problem contains multiple test cases.
A single line with a positive integer TT, the number of test cases.
For each test case:
A single positive integer nn, the number of vertices.

Output Format

For each test case:
Output a single integer, the answer modulo 109+710^9+7. If no graph on nn vertices satisfies the condition, output -1.

6
1
2
3
4
5
6

0
-1
-1
-1
-1
9

Hint

Test point Constraints
11 n,T6n, T \le 6
22 n,T10n, T \le 10
3,43,4 n,T100n, T \le 100
5,65,6 n105n \le 10^5
7,87,8 n109n \le 10^9
99 n1018n \le 10^{18}
1010 n=10100n=10^{100}

For 100%100\% of the testdata, 1n101001 \le n \le 10^{100}, 1T1041 \le T \le 10^4.

Translated by ChatGPT 5