标签:
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 1E6 + 10;
int c[maxn];
int main(){
int t;
//freopen("in.txt","r",stdin);
scanf("%d",&t);
while(t--){
int n,tmp;
scanf("%d",&n);
memset(c,0,sizeof(c));
int curmax = 0;
for(int i = 0;i < n ; ++i){
scanf("%d",&tmp);
++c[tmp];
if(tmp > curmax) curmax = tmp;
}
long long ans = 0;
for(int i = 2 ; i <= curmax ; ++i){
if(!c[i]) continue;
ans += (long long)(c[i] - 1)*c[i] / 2;
for(int j = i * 2 ;j <= curmax ;j += i){
if(!c[j]) continue;
ans += c[i]*c[j];
}
}
printf("%I64d\n",ans);
}
return 0;
}
[2016-04-17][Gym][100947][I][What a Mess]
标签:
原文地址:http://www.cnblogs.com/qhy285571052/p/4cd90d23012f727af347210c1fa56a79.html