#include <bits/stdc++.h>
#define lg(a) (31 - __builtin_clz((a)))
#define endl ("\n")
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define vi vector<int>
#define all(aa) aa.begin(), aa.end()
#define forn(i, n) for(int i=0;i<n;i++)
#define trav(e, x) for(auto& e:x)
#define until(n, v) (int) (lower_bound(v.begin(), v.end(), n)-v.begin()) //# of elements < n
#define after(n, v) (int) (v.end()-upper_bound(v.begin(), v.end(), n)) //# of elements > n
#define sameas(n, v) (int) (upper_bound(v.begin(), v.end(), n) - lower_bound(v.begin(), v.end(), n)) //# of elements ==n
typedef long long ll;
using namespace std;
/*
*/
// vector<int> factorize(int n){
// int prime=0;
// vector<pair<int, int>> p;
// for(int i=2;i*i<=n;i++){
// if(n%i==0){
// p.pb(mp(i, 1));
// prime++:
// }
// while(n%i==0){
// p.back().second++;
// }
// }
// for(int i=0;i<(1<<prime);i++){
// }
// }
vector<int> factorize(int n){
vector<int> p;
p.pb(1);
for(int i=2;i<=n/2;i++){
if(n%i==0){
p.pb(i);
}
}
p.pb(n);
return p;
}
void solve(){
int n, k; cin>>n>>k;
vi v(n), cnt(1e6+5, 0);
for(auto &e:v){
cin>>e; cnt[e]++;
}
vi sorted(v);
sort(all(sorted));
for(int i=0; i<n;i++){
int ans = 0;
if(v[i] >= k){
if(v[i] == k){
ans = after(k, sorted);
}
vi p(factorize(abs(v[i]-k)));
for(auto e : p){
if(e > k) ans+= cnt[e] - (e==v[i]);
}
}
cout<<ans<<' ';
}
}
int main(){
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1342 ms |
4356 KB |
Output is correct |
2 |
Correct |
1348 ms |
4432 KB |
Output is correct |
3 |
Execution timed out |
2037 ms |
5384 KB |
Time limit exceeded |
4 |
Execution timed out |
2054 ms |
6792 KB |
Time limit exceeded |
5 |
Execution timed out |
2025 ms |
5124 KB |
Time limit exceeded |
6 |
Execution timed out |
2040 ms |
6688 KB |
Time limit exceeded |
7 |
Execution timed out |
2048 ms |
5204 KB |
Time limit exceeded |
8 |
Execution timed out |
2021 ms |
5248 KB |
Time limit exceeded |
9 |
Execution timed out |
2051 ms |
6692 KB |
Time limit exceeded |
10 |
Execution timed out |
2052 ms |
6792 KB |
Time limit exceeded |