套娃?
问题
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T,n,x,y,ans;
map<ll,ll> mp;
int main() {
cin>>T;
while(T--){
cin>>n;
mp.clear();
for(int i=1;i<=n;i++){
cin>>x;
mp[x]++;
}ans=0;
for(auto it:mp){
if(it.second>=3) ans+=it.second*(it.second-1)*(it.second-2);
for(int i=1;i*i<it.first;i++){
if(i!=1&&it.first%i==0){
x=it.first/i,y=it.first*i;
if(mp.count(x)!=0&&mp.count(y)!=0) ans+=mp[x]*mp[y]*it.second;
}if(it.first%i==0){
x=i,y=it.first/i*it.first;
if(mp.count(x)!=0&&mp.count(y)!=0) ans+=mp[x]*mp[y]*it.second;
}
}if(sqrt(it.first)*sqrt(it.first)==it.first&&sqrt(it.first)!=1){
x=sqrt(it.first),y=it.first/x*it.first;
if(mp.count(x)!=0&&mp.count(y)!=0) ans+=mp[x]*mp[y]*it.second;
}
}cout<<ans<<endl;
}
return 0;
}