#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
#define f first
#define s second
#define mkp make_pair
#define pii pair<int, int>
const int MAXN = 1e5 + 5;
const int MAXP = 1e7 + 5;
int n;
int v[MAXN];
int dist[MAXP];
int rdist[MAXP];
int sieve[MAXP];
map<int, int> vis;
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
fill(dist, dist + MAXP, 1e9);
fill(rdist, rdist + MAXP, 1e9);
cin >> n;
for(int i = 0; i < n; i++){
cin >> v[i];
vis[v[i]]++;
}
sort(v, v + n, greater<int>());
for(auto x : vis){
for(int i = x.f; i < MAXP; i += x.f){
sieve[i]++;
}
}
for(int i = 1; i < MAXP; i++){
if(sieve[i] > 0) dist[i] = 0;
dist[i] = min(dist[i], dist[i - 1] + 1);
}
for(auto x : vis){
if(sieve[x.f] == 1) dist[x.f] = min(dist[x.f - 1] + 1, v[n - 1]);
x.s = -1;
}
for(int i = 0; i < n; i++){
rdist[v[i]] = 0;
}
for(int i = MAXN - 2; i >= 1; i--){
rdist[i] = min(rdist[i], rdist[i + 1] + 1);
}
for(auto &x : vis){
if(x.s = -1){
x.s = 1e9;
for(int i = 2 * x.f; i < MAXP; i += x.f){
x.s = min(x.s, rdist[i]);
}
}
}
int ans = 0;
for(int i = 0; i < n; i++){
int curr = v[i] - dist[v[i]];
for(int j = 1; j * j <= curr; j++){
if(curr % j == 0){
dist[j] = 0;
dist[curr / j] = 0;
}
}
// cout << dist[v[i]] << ' ' << vis[v[i]] << '\n';
ans += min(dist[v[i]], vis[v[i]]);
}
cout << ans << '\n';
return 0;
}
Compilation message
sirni.cpp: In function 'int32_t main()':
sirni.cpp:52:16: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
52 | if(x.s = -1){
| ~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
49 ms |
195664 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
194 ms |
235360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
45 ms |
199564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
397 ms |
242016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
109 ms |
236112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
507 ms |
242000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
297 ms |
237744 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
636 ms |
242512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
612 ms |
242260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
158 ms |
236676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |