1609C.md (3192B)
1 Source: https://codeforces.com/problemset/problem/1609/C 2 3 C. Complex Market Analysis 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21  22 23 While performing complex market analysis William encountered the following problem: 24 25 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: 26 27 * $1 \le i, k$ 28 * $i + e \cdot k \le n$. 29 * Product $a_i \cdot a_{i + e} \cdot a_{i + 2 \cdot e} \cdot \ldots \cdot a_{i + k \cdot e} $ is a prime number. 30 31 A prime number (or a prime) is a natural number greater than 1 that is not a product of two smaller natural numbers. 32 33 Input 34 35 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10\,000$). Description of the test cases follows. 36 37 The first line of each test case contains two integers $n$ and $e$ $(1 \le e \le n \le 2 \cdot 10^5)$, the number of items in the array and number $e$, respectively. 38 39 The second line contains $n$ integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le 10^6)$, the contents of the array. 40 41 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. 42 43 Output 44 45 For each test case output the answer in the following format: 46 47 Output one line containing the number of pairs of numbers $(i, k)$ which satisfy the conditions. 48 49 Example 50 51 Input 52 53 ``` 54 6 55 7 3 56 10 2 1 3 1 19 3 57 3 2 58 1 13 1 59 9 3 60 2 4 2 1 1 1 1 4 2 61 3 1 62 1 1 1 63 4 1 64 1 2 1 1 65 2 2 66 1 2 67 ``` 68 69 Output 70 71 ``` 72 2 73 0 74 4 75 0 76 5 77 0 78 ``` 79 80 Note 81 82 In the first example test case two pairs satisfy the conditions: 83 84 1. $i = 2, k = 1$, for which the product is: $a_{2} \cdot a_{5} = 2$ which is a prime number. 85 2. $i = 3, k = 1$, for which the product is: $a_{3} \cdot a_{6} = 19$ which is a prime number. 86 87 In the second example test case there are no pairs that satisfy the conditions. 88 89 In the third example test case four pairs satisfy the conditions: 90 91 1. $i = 1, k = 1$, for which the product is: $a_{1} \cdot a_{4} = 2$ which is a prime number. 92 2. $i = 1, k = 2$, for which the product is: $a_{1} \cdot a_{4} \cdot a_{7} = 2$ which is a prime number. 93 3. $i = 3, k = 1$, for which the product is: $a_{3} \cdot a_{6} = 2$ which is a prime number. 94 4. $i = 6, k = 1$, for which the product is: $a_{6} \cdot a_{9} = 2$ which is a prime number. 95 96 In the fourth example test case there are no pairs that satisfy the conditions. 97 98 In the fifth example test case five pairs satisfy the conditions: 99 100 1. $i = 1, k = 1$, for which the product is: $a_{1} \cdot a_{2} = 2$ which is a prime number. 101 2. $i = 1, k = 2$, for which the product is: $a_{1} \cdot a_{2} \cdot a_{3} = 2$ which is a prime number. 102 3. $i = 1, k = 3$, for which the product is: $a_{1} \cdot a_{2} \cdot a_{3} \cdot a_{4} = 2$ which is a prime number. 103 4. $i = 2, k = 1$, for which the product is: $a_{2} \cdot a_{3} = 2$ which is a prime number. 104 5. $i = 2, k = 2$, for which the product is: $a_{2} \cdot a_{3} \cdot a_{4} = 2$ which is a prime number. 105 106 In the sixth example test case there are no pairs that satisfy the conditions.