#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n';
const int M = 2e6+5, MOD = 1e9+7;
int fr[M], ans[M];
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, k;
cin >> n >> k;
vector<int> v(n);
for (int&i:v) cin >> i;
for (int i:v) fr[i]++;
for (int&i:v) i -= k;
for (int i:v) {
if (i < 0) continue;
if (ans[i]) continue;
for (int x = 2; x*x <= i; x++) {
if (i%x == 0) {
if ((i+k)%x == k) ans[i] += fr[x];
if (x*x != i) if ((i+k)%(i/x) == k) ans[i] += fr[i/x];
}
}
}
for (int i:v) ans[0] += i > 0;
for (int i:v) {
if (i >= 0) cout << ans[i] << ' ';
else cout << 0 << ' ';
} cout << endl;
return 0;
}
/*
a%b = k
6 3
4 3 12 6 8 2
0 1 2 3 4 5 6 7 8 9 10 11 12
fr:1 1 0 1 0 0 0 0 0 1 0 0 0
as:0 0 0 0 0 0 0 0 0 0 0 0 0
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
6228 KB |
Output isn't correct |
2 |
Incorrect |
5 ms |
3668 KB |
Output isn't correct |
3 |
Incorrect |
41 ms |
7536 KB |
Output isn't correct |
4 |
Incorrect |
239 ms |
9576 KB |
Output isn't correct |
5 |
Incorrect |
355 ms |
16896 KB |
Output isn't correct |
6 |
Incorrect |
376 ms |
19104 KB |
Output isn't correct |
7 |
Incorrect |
405 ms |
16868 KB |
Output isn't correct |
8 |
Incorrect |
388 ms |
16896 KB |
Output isn't correct |
9 |
Incorrect |
507 ms |
19252 KB |
Output isn't correct |
10 |
Incorrect |
557 ms |
18976 KB |
Output isn't correct |