#P9484. 「LAOI-1」GCD
「LAOI-1」GCD
Problem Description
There is a graph with nodes, numbered . Node is connected to node by an undirected edge with weight if and only if and . Now there are queries. For each query, find the shortest path from to .
Input Format
The first line contains an integer , meaning the number of test cases.
For each test case, the first line contains two positive integers , meaning the number of nodes and the number of queries.
The next lines each contain two positive integers , meaning the start node and the end node.
Output Format
For each query, output one positive integer. Separate adjacent outputs with a newline.
1
6 4
1 4
3 5
2 5
2 4
3
6
5
2
Hint
Pay attention to the time and memory limits. This problem is not bundled.
For of the testdata, .
For of the testdata, , , , and .
Please use faster I/O methods.
updata on 2024/8/8:
The time limit has been increased to 1000 ms. /yun.
Translated by ChatGPT 5