# Pairs of elements

Problem:-

You are given an array of length

$N$

. You are required to count the number of

$\left(i,j\right)$

pairs where

$1⩽i

such that the difference of the array elements on that indices is equal to the sum of the square of their indices.

That is the count of the number of pairs of

$\left(i,j\right)$

such that it satisfies this equation (

$A\left[j\right]-A\left[i\right]={i}^{2}+{j}^{2}$

).

Input format

• The first line contains the length of the array
$N$

. (

$1⩽N⩽{10}^{5}$

)

• The second line contains
$N$

integers representing array elements. (

$1⩽A\left[i\right]⩽{10}^{12}$

)

Output format

Print the number of pairs that satisfy the provided condition.

Sample Input
`54 9 6 29 30`
Sample Output
`3`
Time Limit: 10
Memory Limit: 256
Source Limit:
Explanation

Pairs at indices : (1,2), (2,4), (1,5) satisfy the above condition.

Code:-

You can submit this solution is in c++,c++14 and c++17

#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
long long int a[n+1],i,j;
for( i=1;i<=n;i++)
{
cin>>a[i];
}
long int count=0;
long long int d,f;
for( i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
d=abs(a[j]-a[i]);
f=((i*i)+(j*j));
if(d==f)
count++;
}
}
cout<<count;
return 0;
}