1920C.md (2013B)
1 Source: https://codeforces.com/problemset/problem/1920/C 2 3 C. Partitioning the Array 4 5 time limit per test 6 7 3 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 Allen has an array $a_1, a_2,\ldots,a_n$. For every positive integer $k$ that is a divisor of $n$, Allen does the following: 22 23 * He partitions the array into $\frac{n}{k}$ disjoint subarrays of length $k$. In other words, he partitions the array into the following subarrays: $$[a_1,a_2,\ldots,a_k],[a_{k+1}, a_{k+2},\ldots,a_{2k}],\ldots,[a_{n-k+1},a_{n-k+2},\ldots,a_{n}]$$ 24 * Allen earns one point if there exists some positive integer $m$ ($m \geq 2$) such that if he replaces every element in the array with its remainder when divided by $m$, then all subarrays will be identical. 25 26 Help Allen find the number of points he will earn. 27 28 Input 29 30 Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. The description of the test cases follows. 31 32 The first line of each test case contains a single integer $n$ ($1 \leq n \leq 2\cdot10^5$) — the length of the array $a$. 33 34 The second line of each test case contains $n$ integers $a_1, a_2,\ldots, a_n$ ($1 \leq a_i \leq n$) — the elements of the array $a$. 35 36 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. 37 38 Output 39 40 For each test case, output a single integer — the number of points Allen will earn. 41 42 Example 43 44 Input 45 46 ``` 47 8 48 49 4 50 51 1 2 1 4 52 53 3 54 55 1 2 3 56 57 5 58 59 1 1 1 1 1 60 61 6 62 63 1 3 1 1 3 1 64 65 6 66 67 6 2 6 2 2 2 68 69 6 70 71 2 6 3 6 6 6 72 73 10 74 75 1 7 5 1 4 3 1 3 1 4 76 77 1 78 79 1 80 ``` 81 82 Output 83 84 ``` 85 2 86 1 87 2 88 4 89 4 90 1 91 2 92 1 93 ``` 94 95 Note 96 97 In the first test case, $k=2$ earns a point since Allen can pick $m = 2$ and both subarrays will be equal to $[1, 0]$. $k=4$ also earns a point, since no matter what $m$ Allen chooses, there will be only one subarray and thus all subarrays are equal. 98 99 In the second test case, Allen earns $1$ point for $k=3$, where his choice for $m$ does not matter.