#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
void solve(){
int n,k;
cin>>n>>k;
vector <int> v(n);
for(auto &i:v) cin>>i;
if(k == 0){
map <int,int> mp;
for(auto i : v) mp[i] ++;
int cnt=0;
vector <int> ans(n);
for(auto i : v){
for(int j=1;j*j<=i;j++){
if(i == j){
ans[cnt] += mp[i]-1;
if(i == 1){
ans[cnt] += mp[i]-1;
}
else ans[cnt] += mp[1];
}
else {
if(i % j == 0){
ans[cnt] += mp[j];
if(j == (i/j)) continue;
if(i == (i/j)){
ans[cnt] += mp[i]-1;
}
else {
if(i % (i/j) == 0) ans[cnt] += mp[i/j];
}
}
}
}
cnt ++;
}
for(auto i : ans){
cout<<i<<" ";
}
cout<<endl;
}
else {
set <int> s;
map <int,int> mp;
for(auto i : v){
mp[i] ++;
s.insert(i);
}
map <int,int> ans;
for(auto i : s){
for(auto j : s){
if(i != j){
if(i%j == k) ans[i] += mp[j];
}
else {
if(i%j == k) ans[i] += mp[j]-1;
}
}
}
for(auto i : v) cout<<ans[i]<<" ";
cout<<endl;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
544 KB |
Output is correct |
2 |
Correct |
12 ms |
460 KB |
Output is correct |
3 |
Correct |
91 ms |
1220 KB |
Output is correct |
4 |
Correct |
167 ms |
2756 KB |
Output is correct |
5 |
Correct |
696 ms |
8656 KB |
Output is correct |
6 |
Execution timed out |
2072 ms |
10356 KB |
Time limit exceeded |
7 |
Execution timed out |
2084 ms |
10084 KB |
Time limit exceeded |
8 |
Execution timed out |
2085 ms |
10108 KB |
Time limit exceeded |
9 |
Execution timed out |
2077 ms |
10064 KB |
Time limit exceeded |
10 |
Execution timed out |
2092 ms |
9948 KB |
Time limit exceeded |