Codeforces Round 1095 (Div. 2)
B
Everything Everywhere
Codeforces
900
原题
← AC →
翻译中…

An array is called good if the difference between the maximum value and the minimum value in the array is equal to the greatest common divisor (GCD) of all the elements in the array. Note that an empty array is considered to be not good.

翻译中…

More formally, an array $[a_1, a_2, \ldots, a_m]$ is good if and only if $$ \max(a_1, a_2, \ldots, a_m) - \min(a_1, a_2, \ldots, a_m) = \gcd(a_1, a_2, \ldots, a_m).$$

翻译中…

You are given a permutation$^{\text{∗}}$ $p$ of length $n$. Determine the number of good subarrays$^{\text{†}}$ in the given permutation.

翻译中…

$^{\text{∗}}$A permutation of length $m$ is an array consisting of $m$ distinct integers from $1$ to $m$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($m=3$ but there is $4$ in the array). $^{\text{†}}$An array $b$ is a subarray of an array $a$ if $b$ can be obtained from $a$ by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. In particular, an array is a subarray of itself.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each testcase contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the length of the permutation $p$.

翻译中…

The second line of each testcase contains $n$ integers $p_1, p_2, \ldots, p_n$ ($1 \le p_i \le n$) — the permutation $p$. It is guaranteed that $p$ is a permutation.

翻译中…

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

翻译中…

Output

翻译中…

For each testcase, print a single integer — the number of good subarrays in the given permutation.

翻译中…

Note

翻译中…

For the first testcase, only one subarray is good, which is $[1, 2]$.

翻译中…

For the second testcase, it can be proven that no good subarrays exist in the given permutation.

翻译中…

样例

Input #1
3
2
1 2
9
6 1 5 9 4 7 2 8 3
4
1 2 3 4
Output #1
1
0
3
InputCopy OutputCopy
题目信息
题号
2226B
时间限制
1.5 s
内存限制
256 MB
标签
贪心
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。