#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int gcd(int a,int b)
{
int r=b;
while(r!=0)
{
r = a%b;
a = b;
b = r;
}
return a;
}
#define M 805
int a[M];
int nogcd[M];
int exsitgcd[M];
void init()
{
int test;
cin>>test;
while(test--)
{
memset(a,0,sizeof(a));
memset(nogcd,0,sizeof(nogcd));
memset(exsitgcd,0,sizeof(exsitgcd));
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
{
int d = gcd(a[i],a[j]);
if(d==1) {nogcd[i]++;nogcd[j]++;}
else exsitgcd[i]++,exsitgcd[j]++;
}
int sum = 0;
for(int i=0;i<n;i++)
sum += nogcd[i]*exsitgcd[i];
printf("%d\n",n*(n-1)*(n-2)/6-sum/2);
}
}
int main()
{
init();
return 0;
}
hdu 3908
最新推荐文章于 2015-04-23 22:53:18 发布