问题描述
- 给一个组数,找出一共有多少对
(
i
,
j
)
(i,j)
(i,j)符合
i
<
j
i < j
i<j并且
a
i
×
a
j
=
i
+
j
a_i\times a_j = i + j
ai×aj=i+j
思路分析
代码如下
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 10;
ll a[maxn];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
int ans = 0;
for (ll i = 1; i <= n; i++)
{
for (ll j = a[i] - i; j <= n; j += a[i])
{
if (j <= i)
continue;
else if ((i + j) == (a[i] * a[j]))
{
ans++;
}
}
}
cout << ans << endl;
}
return 0;
}