codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

2196B.md (1314B)


      1 Source: https://codeforces.com/problemset/problem/2196/B
      2 
      3 B. Another Problem about Beautiful Pairs
      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 In the array $a$, we call a pair of indices $i$, $j$ beautiful if the following condition holds:
     22 
     23 * $a_{i} \cdot a_{j} = j - i$.
     24 
     25 Count the number of beautiful pairs in the array $a$.
     26 
     27 Input
     28 
     29 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.
     30 
     31 The first line of each test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^{5}$).
     32 
     33 The second line of each test case contains $n$ integers $a_{i}$ ($1 \le a_{i} \le 10^{9}$).
     34 
     35 Additional constraints on the input:
     36 
     37 * The sum of $n$ across all test cases does not exceed $2 \cdot 10^5$.
     38 
     39 Output
     40 
     41 For each test case, output a single integer — the answer to the problem.
     42 
     43 Example
     44 
     45 Input
     46 
     47 ```
     48 4
     49 
     50 5
     51 
     52 1 1 2 100 4
     53 
     54 6
     55 
     56 2 2 1 1 2 2
     57 
     58 10
     59 
     60 1 1 2 3 4 1 1 7 3 9
     61 
     62 2
     63 
     64 1000000000 1000000000
     65 ```
     66 
     67 Output
     68 
     69 ```
     70 3
     71 
     72 7
     73 
     74 10
     75 
     76 0
     77 ```
     78 
     79 Note
     80 
     81 In the first example, there are $3$ beautiful pairs: ($1, 2$), ($1, 3$), and ($1, 5$).
     82 
     83 In the second example, there are $7$ beautiful pairs: ($1, 3$), ($1, 5$), ($2, 4$), ($2, 6$), ($3, 4$), ($3, 5$), and ($4, 6$).