#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);
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(k%e!=0) ans+= cnt[e] - (e==v[i]);
}
}
cout<<ans<<' ';
}
}
int main(){
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
496 ms |
8452 KB |
Execution killed with signal 8 |
2 |
Runtime error |
519 ms |
8452 KB |
Execution killed with signal 8 |
3 |
Execution timed out |
2041 ms |
5124 KB |
Time limit exceeded |
4 |
Execution timed out |
2064 ms |
6688 KB |
Time limit exceeded |
5 |
Execution timed out |
2055 ms |
5128 KB |
Time limit exceeded |
6 |
Execution timed out |
2087 ms |
6692 KB |
Time limit exceeded |
7 |
Execution timed out |
2062 ms |
5128 KB |
Time limit exceeded |
8 |
Runtime error |
1857 ms |
9992 KB |
Execution killed with signal 8 |
9 |
Execution timed out |
2045 ms |
6688 KB |
Time limit exceeded |
10 |
Execution timed out |
2036 ms |
6684 KB |
Time limit exceeded |