Problem: Given an array of length . Let's construct a square matrix of size , in which the -th row contains the array cyclically shifted to the right by . For example, for the array , the obtained matrix is
Let's construct the following graph:
- The graph contains vertices, each of which corresponds to one of the elements of the matrix. Let's denote the vertex corresponding to the element as .
- We will draw an edge between vertices and if and , where denotes the greatest common divisor of integers and .
Your task is to calculate the number of connected components in the obtained graph.
A connected component of a graph is a set of vertices in which any vertex is reachable from any other via edges, and adding any other vertex to the set violates this rule.
Input Format: Each test consists of multiple test cases. The first line contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers and (, ) — the length of the array and the parameter .
The second line of each test case contains integers () — the elements of the array .
It is guaranteed that the sum of over all test cases does not exceed .
Output Format: For each test case, output a single integer — the number of connected components in the obtained graph.
Note: In the first test case, the matrix is given in the statement. The first connected component contains the vertices , , and . The second connected component contains the vertices , , and . The third connected component contains the vertices , , and . Thus, the graph has connected components.
In the second test case, the following matrix is obtained:
The first connected component contains all vertices corresponding to elements with values and . The second connected component contains all vertices corresponding to elements with the value .
In the fourth test case, all vertices are in one connected component.