May be you can try in this approach
simplify the equation
(Aj)^2 + AiAj - Ai = 0
quadratic eqn formula
Aj = (-Ai + sqrt(Ai^2 + 4Ai))/2;
check for every element in Array, if the sqrt possible and any integer element found in the array
there will be a pair
Thanks a lot for the help
Can you please check this solution its giving TLE .
Through the given equation we can get that Ai= ( Aj*Aj )/( 1-Aj )
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
//write your code here
int t ; cin>>t ;
for(int i=0;i<t;i++)
{ unordered_map<double,vector<ll>>map;
int n ; cin>>n; ll arr[n];
for(int j=0;j<n;j++)
{ cin>>arr[j]; map[arr[j]].push_back(j);}
ll ans=0;
for(int g=0;g<n;g++)
{
if(arr[g]!=1)
{
double d=(arr[g]*arr[g])/(1-arr[g]);
if(map.find(d)!=map.end())
{
for(int r=0;r<map[d].size();r++)
{
if(map[d][r]<g)
{
ans++;
}
else
{
break;
}
}
}
}
}
cout<<ans<<endl;
}
return 0;
}
```**strong text**
dont insert the index in the map , just count the frequency of the element inside the map
just tranverse the map
all data types must be integers,dont use double,just try to check
(arr[g]arr[g])/1-arr[g] must be a integer
if it is not a integer
move on
if it is a integer
get the frequencies from the map
mp[a] = x;mp[b] = y;
number of pairs = x*y;
try in this approach
Hello @ajithhtija , can you please provide the solution to this problem am unable to code the correct solution.
problem link:- PrepBytes
Also try this test case
input
1
4
-3 -3 -3 2
output
3
Explanation :- I am writing the index of the pair
(0,3) (1,3) (2,3)
Ai+Aj = -3+2 =-1 and Ai/Aj = -3/2 = -1
so, Ai+Aj = Ai/Aj also i<j
Please help me to solve this question also try the above testcase.
I think this link will help you rather than me check it
the above link is an accepted solution there he considers A[i]/A[j] must be a integer value
1
4
-3 -3 -3 2
for this test case the crct ouput:0
Thanks for the help