#P5448. [THUPC 2018] 好图计数
[THUPC 2018] 好图计数
Description
We define an undirected simple graph to be good as follows:
-
A single vertex is good.
-
A graph formed by taking several good graphs as connected components is good.
-
The complement of a good graph is good.
Given a positive integer .
Find, modulo the prime , the number of essentially different good graphs on vertices. (Here is a constant; see Input Format for details.)
Two good graphs are considered essentially different if and only if, no matter how you relabel one graph, it still cannot become exactly the same as the other graph.
Input Format
The input contains multiple test cases. The first line contains two integers separated by spaces, representing the number of test cases and the modulus. Then each test case is described as follows:
- One line with one integer , meaning the number of vertices of the good graphs to be counted.
Output Format
For each test case, output one line:
- One integer, the number of good graphs on vertices modulo .
2 233
3
4
4
10
Hint
Sample Explanation
Below are all good graphs with vertices:

Constraints
It is guaranteed that , , , and is prime.
Hint
The time complexity of an algorithm that can pass this problem might be worse than you expect, or it might be better than you expect.
Copyright Information
From the 2018 Tsinghua University Programming Contest and Collegiate Invitational (THUPC2018). Thanks to Pony.ai for supporting this contest.
Resources such as editorials can be found at https://github.com/wangyurzee7/THUPC2018.
Translated by ChatGPT 5
京公网安备 11011102002149号