​传送门​

Codeforces Round #728 (Div. 2)-B. Pleasant Pairs_i++

题意:

给你一串数字,求满足Codeforces Round #728 (Div. 2)-B. Pleasant Pairs_#define_02且i<j的序列对数。

思路:

对于第i个数,仅当下标j满足Codeforces Round #728 (Div. 2)-B. Pleasant Pairs_#include_03时合法,也就是说,每次应选择j+i为Codeforces Round #728 (Div. 2)-B. Pleasant Pairs_i++_04的倍数的下标。

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<map>
#include<queue>
#include<math.h>
using namespace std;
#define ll long long
#define mod 4933ll
ll a[100010];

int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
for(int i = 1; i <= n; i++)
{
cin>>a[i];
}
ll ans = 0;
for(ll i = 1; i <= n; i++)
{
ll j = a[i]-i;
if(j < i)
{
ll k = 2*i/a[i];
j = k*a[i]-i+a[i];

}
for(; j <= n; j+=a[i])
{
if(a[i]*a[j]==i+j) ans++;
}
}
cout<<ans<<endl;
}
}