Help me in solving EQPAIR problem

My issue

My code

#include <iostream>
using namespace std;
#include <bits/stdc++.h>
# define ll long long int
int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    ll n,c=0;
	    cin>>n;
	    set<ll>A;
	    for(int i=0;i<n;i++)
	    cin>>A.insert;
	    for(int i=0;i<n-1;i++)
	    {
	        for(int j=i+1;j<n;j++)
	        {
	            //for HCF
	            while(A[i]!=A[j])
	            {
	                if(A[i]>A[j])
	                A[i]-=A[j];
	                else
	                A[j]-=A[i];
	            }
	            ll h=A[i];
	            // for lcm
	            ll l=(A[i]*A[j])/h;
	            if(h==l)
	            c++;
	        }
	    }
	    cout<<c<<endl;
	}
	return 0;
}

Problem Link: EQPAIR Problem - CodeChef

@rajukumar22
U can’t do it in O(n^2) complexity bcozz of high constraints:-
one hint for gcd==hcf both number should be same like 2,2 or 3,3 if they differ its not possible