#P10394. 接连不断!
接连不断!
Background
The little frog was locked in a small dark room in prison, suffering nonstop torture, both physically and mentally.
His mind is exhausted, and his body moves slowly.
Some things have been temporarily suppressed, but the more they are suppressed, the stronger the backlash will be when they rebound.
He needs a trigger.
Problem Description
The frog has undirected graphs, numbered . The vertex set of each graph is , and contains vertices numbered . At the beginning, none of the graphs has any edges.
Next, in the graph with number , for every in , the frog will connect vertex and vertex with an undirected edge.
He wants to know, among these graphs, how many graphs are connected. Please answer this question.
Notes:
- means modulo. is the remainder when is divided by .
- In a graph, if for any two different vertices in the vertex set there exists at least one path between them, then we call this graph connected.
Input Format
This problem contains multiple test cases.
The first line contains an integer , which is the number of test cases.
The next lines each contain two integers , with the same meaning as above.
Output Format
Output lines. Each line contains one integer, the answer for that test case.
3
3 2
4 4
5 5
1
3
2
5
4 3
4 4
4 5
4 6
4 7
2
3
3
4
4
3
1145 1499
12344 123456
114514 1919810
2
41
17
Hint
[Sample #1 Explanation]
Query 1:
| Graph number | Edge set | Is the graph connected |
|---|---|---|
| Yes | ||
| No | ||
Query 2:
| Graph number | Edge set | Is the graph connected |
|---|---|---|
| Yes | ||
| No | ||
| Yes | ||
| No | ||
| Yes |
Query 3:
| Graph number | Edge set | Is the graph connected |
|---|---|---|
| Yes | ||
| No | ||
| Yes |
So the answers are .
[Constraints]
This problem uses bundled testdata.
| Constraints | Score | |
|---|---|---|
- For of the testdata, it is guaranteed that and .
Translated by ChatGPT 5