Codeforces 1541B - Pleasant Pairs Solution
///******Bismillahir-Rahmanir-Rahim******///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
long long t,n,i,j,a,c;
pair<long long,long long>p[100009];
cin>>t;
while(t--)
{
cin>>n;
for(i=1; i<=n; i++)
{
cin>>a;
p[i]= {a,i};
}
c=0;
sort(p+1,p+1+n);
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if((p[i].first*p[j].first)>n+n)
break;
else
{
if((p[i].first*p[j].first)==p[i].second+p[j].second)
c++;
}
}
}
cout<<c<<endl;
}
return 0;
}
No comments