bdfz_2024_summer/day12/U466180/tx.cpp

40 lines
654 B
C++

#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;
}