← Home
write a go solution for Description:
While performing complex market analysis William encountered the following problem:

For a given array a of size n and a natural number e, calculate the number of pairs of natural numbers (i,k) which satisfy the following conditions:

- 1<=i,k
- i+e*k<=n.
- Product a_i*a_i+e*a_i+2*e*ldots*a_i+k*e is a prime number.

A prime number (or a prime) is a natural number greater than 1 that is not a product of two smaller natural numbers.

Input Format:
Each test contains multiple test cases. The first line contains the number of test cases t (1<=t<=10,000). Description of the test cases follows.

The first line of each test case contains two integers n and e (1<=e<=n<=2*10^5), the number of items in the array and number e, respectively.

The second line contains n integers a_1,a_2,...,a_n (1<=a_i<=10^6), the contents of the array.

It is guaranteed that the sum of n over all test cases does not exceed 2*10^5.

Output Format:
For each test case output the answer in the following format:

Output one line containing the number of pairs of numbers (i,k) which satisfy the conditions.

Note:
In the first example test case two pairs satisfy the conditions:

1. i=2,k=1, for which the product is: a_2*a_5=2 which is a prime number.
2. i=3,k=1, for which the product is: a_3*a_6=19 which is a prime number.

In the second example test case there are no pairs that satisfy the conditions.

In the third example test case four pairs satisfy the conditions:

1. i=1,k=1, for which the product is: a_1*a_4=2 which is a prime number.
2. i=1,k=2, for which the product is: a_1*a_4*a_7=2 which is a prime number.
3. i=3,k=1, for which the product is: a_3*a_6=2 which is a prime number.
4. i=6,k=1, for which the product is: a_6*a_9=2 which is a prime number.

In the fourth example test case there are no pairs that satisfy the conditions.

In the fifth example test case five pairs satisfy the conditions:

1. i=1,k=1, for which the product is: a_1*a_2=2 which is a prime number.
2. i=1,k=2, for which the product is: a_1*a_2*a_3=2 which is a prime number.
3. i=1,k=3, for which the product is: a_1*a_2*a_3*a_4=2 which is a prime number.
4. i=2,k=1, for which the product is: a_2*a_3=2 which is a prime number.
5. i=2,k=2, for which the product is: a_2*a_3*a_4=2 which is a prime number.

In the sixth example test case there are no pairs that satisfy the conditions.. Output only the code with no comments, explanation, or additional text.