#include<bits/stdc++.h>
#define int long long
#define pb(x) push_back(x)
#define in(x) insert(x)
#define F first
#define S second
#define endl '\n'
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
const int M=1e9+7;
const int N=1e6+10;
using namespace std;
int freq[N];
int32_t main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,c;
cin>>n>>c;
int a[n+10] , ans[n+10]={0} , b[n+10];
for(int i=1;i<=n;i++){
cin>>a[i];
b[i] = a[i];
freq[a[i]]++;
}
for(int i=1;i<=n;i++)
{
int cur = a[i] - c;
for(int j=1;j*j<=cur;j++)
{
if(cur % j == 0)
{
int f = j , s = cur/j;
if(cur + f > a[i])
ans[i] += freq[f] - (f == a[i]);
if(cur + s > a[i]){
if(f != s)
ans[i] += freq[s] - (s == a[i]);
}
}
}
}
sort(a+1,a+1+n);
int idx = n;
for(int i=n;i>=1;i--)
{
if(a[i] == c)
{
idx = i;
break;
}
}
for(int i=1;i<=n;i++){
if(b[i] == c)
ans[i] += n-idx;
cout<<ans[i]<<' ';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
7260 KB |
Output is correct |
2 |
Correct |
7 ms |
7000 KB |
Output is correct |
3 |
Correct |
271 ms |
10496 KB |
Output is correct |
4 |
Correct |
789 ms |
16868 KB |
Output is correct |
5 |
Correct |
310 ms |
11240 KB |
Output is correct |
6 |
Correct |
907 ms |
17984 KB |
Output is correct |
7 |
Correct |
358 ms |
11248 KB |
Output is correct |
8 |
Correct |
357 ms |
11252 KB |
Output is correct |
9 |
Correct |
1045 ms |
18008 KB |
Output is correct |
10 |
Correct |
1045 ms |
17760 KB |
Output is correct |