CF1541B.Pleasant Pairs

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array a1,a2,…,ana_1, a_2, \dots, a_n consisting of nn distinct integers. Count the number of pairs of indices (i,j)(i, j) such that i<ji \lt j and ai⋅aj=i+ja_i \cdot a_j = i + j.

给你一个由 nn 个互不相同的整数组成的数组 a1,a2,…,ana_1, a_2, \dots, a_n。请计算满足 i<ji \lt j 且 ai⋅aj=i+ja_i \cdot a_j = i + j 的索引对 (i,j)(i, j) 的数量。

输入格式

The first line contains one integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. Then tt cases follow.

The first line of each test case contains one integer nn (2≤n≤1052 \leq n \leq 10^5) — the length of array aa.

The second line of each test case contains nn space separated integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤2⋅n1 \leq a_i \leq 2 \cdot n) — the array aa. It is guaranteed that all elements are distinct.

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

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)——测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含一个整数 nn(2≤n≤1052 \leq n \leq 10^5)——数组 aa 的长度。

每个测试用例的第二行包含 nn 个以空格分隔的整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤2⋅n1 \leq a_i \leq 2 \cdot n)——数组 aa。保证所有元素互不相同。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output the number of pairs of indices (i,j)(i, j) such that i<ji \lt j and ai⋅aj=i+ja_i \cdot a_j = i + j.

对于每个测试用例,输出满足 i<ji \lt j 且 ai⋅aj=i+ja_i \cdot a_j = i + j 的索引对 (i,j)(i, j) 的数量。

输入输出样例

  • 输入#1

    3
    2
    3 1
    3
    6 1 5
    5
    3 1 5 9 2

    输出#1

    1
    1
    3

说明/提示

For the first test case, the only pair that satisfies the constraints is (1,2)(1, 2), as a1⋅a2=1+2=3a_1 \cdot a_2 = 1 + 2 = 3

For the second test case, the only pair that satisfies the constraints is (2,3)(2, 3).

For the third test case, the pairs that satisfy the constraints are (1,2)(1, 2), (1,5)(1, 5), and (2,3)(2, 3).

对于第一个测试用例,唯一满足约束条件的数对是 (1,2)(1, 2),因为 a1⋅a2=1+2=3a_1 \cdot a_2 = 1 + 2 = 3。

对于第二个测试用例,唯一满足约束条件的数对是 (2,3)(2, 3)。

对于第三个测试用例,满足约束条件的数对有 (1,2)(1, 2)、(1,5)(1, 5) 和 (2,3)(2, 3)。

输入解题思路,AI测评打分。不知道怎么写?

首页