#include <bits/stdc++.h>
#define all(v) ((v).begin(),(v).end())
using namespace std;
#define int long long
const int mod = 1e9 + 7;
const int mxN = 2e6 + 1;
int a[mxN];
int fr[mxN];
int ans[mxN];
int gr[mxN];
signed main()
{
cin.tie(0);cout.tie(0);
ios_base::sync_with_stdio(0);
int n,k;
cin >>n>>k;
int num = 0;
for(int i = 0;i < n;i++){
cin >>a[i];
if(a[i] > k)
num++;
fr[a[i]]++;
}
for(int i = 0;i < n;i++){
if(a[i] > k){
int x = a[i] - k;
for(int j = 1;j * j <= x;j++){
if(x % j == 0){
if(j > k && j){
if(j == a[i])
ans[i] += fr[j] - 1;
else
ans[i] += fr[j];
}
if(x / j > k && x/ j != j){
if(x / j == a[i])
ans[i] += fr[x / j] - 1;
else
ans[i] += fr[x / j];
}
}
}
}else if(a[i] == k){
ans[i] = num;
}
cout<<ans[i]<<' ';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
3412 KB |
Output is correct |
2 |
Correct |
7 ms |
2132 KB |
Output is correct |
3 |
Correct |
282 ms |
5852 KB |
Output is correct |
4 |
Correct |
814 ms |
10084 KB |
Output is correct |
5 |
Correct |
328 ms |
10628 KB |
Output is correct |
6 |
Correct |
944 ms |
14876 KB |
Output is correct |
7 |
Correct |
370 ms |
10572 KB |
Output is correct |
8 |
Correct |
372 ms |
10572 KB |
Output is correct |
9 |
Correct |
1079 ms |
14552 KB |
Output is correct |
10 |
Correct |
1075 ms |
14816 KB |
Output is correct |