P2926. Patting Heads S

考点

  • 质数

题解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>
using namespace std;
const int LEN = 1e6 + 50;
int n, arr[LEN], cnt[LEN], w[LEN];

int main() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> arr[i], ++cnt[arr[i]];
for (int i = 1; i <= 1e6; ++i) {
for (int j = i; j <= 1e6; j += i) {
w[j] += cnt[i];
}
}
for (int i = 1; i <= n; ++i) {
cout << w[arr[i]] - 1 << endl;
}
return 0;
}

思路

《深基》的教学题,直接上图