bdfz_2024_summer/day12/U466180/U466180.cpp
2024-08-14 15:13:04 +08:00

63 lines
1.4 KiB
C++

//暴力30Points
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAX_N = 1000+5;
int a[MAX_N];
int n,amax=INT_MIN,ans=0;
unordered_map<int,long long> um;
int readint();
signed main(signed argc,char *argv[]){
#ifdef OITEST
#define AS_EQ(a,b){if((a)!=(b)){cerr<<"assert eq faild:"<<endl<<#a<<":"<<(a)<<endl<<#b<<":"<<(b)<<endl;exit(-1);}}
#define AS_NE(a,b){if((a)==(b)){cerr<<"assert not eq faild:"<<endl<<#a<<":"<<(a)<<endl<<#b<<":"<<(b)<<endl;exit(-1);}}
AS_EQ(argc,3)
auto fin = freopen(argv[1],"r",stdin);
AS_NE(fin,NULL)
ifstream afile(argv[2]);
AS_EQ(afile.is_open(),true);
#endif
n=readint();
for(int i=1;i<=n;i++){
a[i]=readint();
}
for(int i=1;i<=n;i++){
int num=a[i];
for(int j=2;j<=sqrt(a[i]);j++){
if(num%j==0){
um[j]+=a[i];
while(num%j==0)num/=j;
}
}
if(num>1){
um[num]+=a[i];
}
}
for(auto i : um){
ans+=i.second;
}
cout<<ans<<endl;
#ifdef OITEST
int cans;
afile>>cans;
AS_EQ(ans,cans)
#endif
}
int readint(){
int x=0,w=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-')w=-1;
ch=getchar();
}
while(isdigit(ch)){
x=x*10+(ch-'0');
ch=getchar();
}
return x*w;
}