[Solution] KBG and GN-Theory CodeChef Solution
After solving some Graph Theory related problems KBG challenged Sameer to solve the following problem.
There is an undirected graph consisting of vertices numbered from to .
For every pair of vertices and in the graph, there is a undirected weighted edge between and if and only if divides , with weight . Note that such a graph will not have self loops or multiple edges.
You must answer queries. In each query you are given two vertices and . You must find the
minimum distance from vertex to vertex .
Input Format
- The first line contains a single integer — the number of test cases. Then the test cases follow.
- The first line of each test case contains two integers and — the number of vertices and the number of queries.
KBG and GN-Theory CodeChef Solution
Retrieve the Array CodeChef Solution
Even Equal Odd CodeChef Solution
Xor and Multiply CodeChef Solution
Chef and his Apps CodeChef Solution
- The next lines contain two space-separated integers and — vertices corresponding to the query.
Output Format
For each test case, print lines — the answers to the queries.
Constraints
- The sum of over all test cases does not exceed .
- The sum of over all test cases does not exceed
No comments:
Post a Comment