#include<bits/stdc++.h>
using namespace std;
#define int ll
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int mod=1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mul(int a,int b)
{
return ((a)*1ll*(b))%mod;
}
void add(int &a,int b)
{
a+=b;
if(a>=mod)a-=mod;
}
int sub(int a,int b){
a-=b;
if(a<0){
a+=mod;
}
return a;
}
int powz(int a,int b)
{
int res=1;
while(b)
{
if(b&1){
res=mul(res,a);
}
b/=2;
a=mul(a,a);
}
return res;
}
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
input>>x.F>>x.S;
return input;
}
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
for(auto& i:x)
input>>i;
return input;
}
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
for(auto& i:x)
output<<i<<' ';
return output;
}
const int N=1000002;
int dp[N],cnt[N];
void solve(){
int n,k;
cin>>n>>k;
vi a(n);
cin>>a;
for(auto i:a){
cnt[i]++;
}
for(int i=N-1;i>k;i--){
for(int j=0;j<N;j+=i){
dp[j+k]+=cnt[i];
}
if(k==0){
dp[i]--;
}
}
for(int i=0;i<n;i++){
cout<<dp[a[i]]<<' ';
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int tc=1;
//~cin>>tc;
for(int _=0;_<tc;_++){
//~ cout<<"Case #"<<_+1<<": ";
solve();
if(_!=tc-1)
cout<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
11256 KB |
Output is correct |
2 |
Correct |
59 ms |
9976 KB |
Output is correct |
3 |
Correct |
113 ms |
12444 KB |
Output is correct |
4 |
Correct |
130 ms |
14584 KB |
Output is correct |
5 |
Correct |
108 ms |
16968 KB |
Output is correct |
6 |
Correct |
170 ms |
19272 KB |
Output is correct |
7 |
Correct |
86 ms |
16956 KB |
Output is correct |
8 |
Correct |
87 ms |
17000 KB |
Output is correct |
9 |
Correct |
149 ms |
19296 KB |
Output is correct |
10 |
Correct |
149 ms |
19164 KB |
Output is correct |