This commit is contained in:
Zengtudor 2024-08-16 10:53:13 +08:00
parent b130e643b8
commit 012325cdda
1 changed files with 40 additions and 40 deletions

View File

@ -1,40 +1,40 @@
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
int a[1005];
int zs[50005];
int tot;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++){
int t=a[i];
for(int j=2;j*j<=t;j++){
if(t%j==0){
zs[++tot]=j;
// cout<<j<<" ";
while(t%j==0)t/=j;
}
}
if(t>1){
//cout<<t<<" ";
zs[++tot]=t;
}
//cout<<endl;
}
sort(zs+1,zs+tot+1);
tot=unique(zs+1,zs+tot+1)-zs-1;
int ans=0;
for(int i=1;i<=tot;i++){
int now=0;
int tt=zs[i];
for(int j=1;j<=n;j++){
if(a[j]%tt==0)now+=a[j];
}
ans=max(ans,now);
}
cout<<ans;
}
// #include<bits/stdc++.h>
// #define int long long
// using namespace std;
// int n;
// int a[1005];
// int zs[50005];
// int tot;
// signed main(){
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
// cin>>n;
// for(int i=1;i<=n;i++)cin>>a[i];
// for(int i=1;i<=n;i++){
// int t=a[i];
// for(int j=2;j*j<=t;j++){
// if(t%j==0){
// zs[++tot]=j;
// // cout<<j<<" ";
// while(t%j==0)t/=j;
// }
// }
// if(t>1){
// //cout<<t<<" ";
// zs[++tot]=t;
// }
// //cout<<endl;
// }
// sort(zs+1,zs+tot+1);
// tot=unique(zs+1,zs+tot+1)-zs-1;
// int ans=0;
// for(int i=1;i<=tot;i++){
// int now=0;
// int tt=zs[i];
// for(int j=1;j<=n;j++){
// if(a[j]%tt==0)now+=a[j];
// }
// ans=max(ans,now);
// }
// cout<<ans;
// }