题目:
题解:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e6;
int a[maxn+5],b[maxn+5];
signed main(){
int n,ans=0,s1=0;
scanf("%lld",&n);
for (int i = 0; i < n; ++i) {
int x;
scanf("%lld",&x);
b[x]++;
if(x==1) s1++;
}
ans=ans+s1*s1*s1;
for (int i = 2; i <= maxn; ++i) {
if(b[i]) ans=ans+s1*b[i]*b[i]*2;
}
for (int i = 2; i <= 1000; ++i) {
if(b[i]) {
for (int j = i; j * i <= maxn; ++j) {
if (j == i && b[i * j]) ans = ans + b[i] * b[i] * b[i * j];
else if (j != i && b[j] && b[i * j])ans = ans + b[i] * b[j] * 2 * b[i * j];
}
}
}
printf("%lld\n",ans);
return 0;
}