#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
int readint(){
int x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,k,h[300005],cnt[1000005],ans[1000005];
int main(){
n=readint(); k=readint();
for(int i=1;i<=n;i++) h[i]=readint();
for(int i=1;i<=n;i++) cnt[h[i]]++;
for(int x=k+1;x<=1000000;x++){
ans[k]+=cnt[x];
for(int y=x;y+k<=1000000;y+=x) ans[y+k]+=cnt[x];
if(k==0) ans[x]--;
}
for(int i=1;i<=n;i++) printf("%d ",ans[h[i]]);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
8796 KB |
Output is correct |
2 |
Correct |
11 ms |
8796 KB |
Output is correct |
3 |
Correct |
20 ms |
9540 KB |
Output is correct |
4 |
Correct |
39 ms |
12116 KB |
Output is correct |
5 |
Correct |
22 ms |
9564 KB |
Output is correct |
6 |
Correct |
49 ms |
12368 KB |
Output is correct |
7 |
Correct |
18 ms |
9556 KB |
Output is correct |
8 |
Correct |
23 ms |
9560 KB |
Output is correct |
9 |
Correct |
40 ms |
11880 KB |
Output is correct |
10 |
Correct |
41 ms |
12112 KB |
Output is correct |