很明显是莫反。
含因子1的-含因子2的-含因子3的+含因子6的···
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 1e4 + 10;
int n, s, p[N], miu[N]; bool v[N];
void get_miu() {
miu[1] = 1;
for (int i = 2; i <= 10000; i++) {
if (!v[i]) p[++s] = i, miu[i] = -1;
for (int j = 1; j <= s && i * p[j] <= 10000; j++) {
v[i * p[j]] = 1;
if (i % p[j] == 0) break;
miu[i * p[j]] = -miu[i];
}
}
}
int sum[N];
LL C(int n, int m) {
if (n < m) return 0;
if (!m) return 1;
double ans = 1.0;
for (int i = 1; i <= m; i++) ans = 1.0 * ans * (n + 1 - i) / i;
return (LL)ans;
}
int main() {
get_miu();
while (cin >> n) {
memset(sum, 0, sizeof(sum));
int m = 0;
for (int i = 1; i <= n; i++) {
int x; scanf("%d", &x);
m = max(m, x);
for (int j = 1; j * j <= x; j++)
if (x % j == 0) {
sum[j]++;
if (j * j != x) sum[x / j]++;
}
}
LL ans = 0;
for (int i = 1; i <= m; i++)
ans += 1ll * miu[i] * C(sum[i], 4);
cout << ans << endl;
}
return 0;
}