Another Problem about Beautiful Pairs
Submit solution
Points:
30 (partial)
Time limit:
3.0s
Memory limit:
98M
Author:
Problem types
Allowed languages
C++
In the array \(a\), we call a pair of indices \(i, j\) beautiful if the following condition holds:
- \(a_i \cdot a_j = j - i\).
Count the number of beautiful pairs in the array \(a\).
Input Specification
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 test case contains a single integer \(n\) (\(2 \le n \le 2 \cdot 10^5\)).
The second line of each test case contains \(n\) integers \(a_i\) (\(1 \le a_i \le 10^9\)).
Additional constraints on the input:
- The sum of \(n\) across all test cases does not exceed \(2 \cdot 10^5\).
Output Specification
For each test case, output a single integer — the answer to the problem.
Examples
Example Input 1
4
5
1 1 2 100 4
6
2 2 1 1 2 2
10
1 1 2 3 4 1 1 7 3 9
2
1000000000 1000000000
Output
3
7
10
0
Note
In the first example, there are \(3\) beautiful pairs: \((1, 2)\), \((1, 3)\), and \((1, 5)\).
Comments