//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
llo n;
bool vis[10000001];
llo ind[10000001];
llo re[10000001+1];
llo par[100001];
llo find(llo no){
if(par[no]==no){
return no;
}
par[no]=find(par[no]);
return par[no];
}
vector<pair<llo,llo>> pre[10000001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
llo ind2=0;
for(llo i=0;i<n;i++){
llo x;
cin>>x;
if(vis[x]==0){
vis[x]=1;
ind[x]=ind2;
//cout<<x<<":"<<ind2<<endl;
ind2++;
}
}
for(llo i=0;i<ind2;i++){
par[i]=i;
}
re[10000001]=-1;
for(llo i=10000000;i>=1;i--){
re[i]=re[i+1];
if(vis[i]==1){
re[i]=i;
}
}
for(llo i=1;i<=10000000;i++){
if(vis[i]==1){
for(llo j=i;j<=10000000;j+=i){
if(re[j]>=0){
pre[re[j]-j].pb({ind[re[j]],ind[i]});
}
}
}
}
llo ans=0;
for(llo i=0;i<=10000000;i++){
for(auto j:pre[i]){
llo x=find(j.a);
llo y=find(j.b);
//cout<<x<<","<<y<<","<<j.a<<","<<j.b<<endl;
if(x==y){
}
else{
ans+=i;
par[x]=y;
}
}
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
234 ms |
320484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
315 ms |
313696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
228 ms |
321140 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
446 ms |
343580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
270 ms |
326700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
669 ms |
368904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
422 ms |
322640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
416 ms |
427328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
443 ms |
436032 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
285 ms |
378360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |