bdfz_2024_summer/day12/U466180/U466180.cpp

63 lines
1.4 KiB
C++
Raw Normal View History

2024-08-14 03:47:41 +00:00
//暴力30Points
2024-08-14 00:19:09 +00:00
#include<bits/stdc++.h>
using namespace std;
2024-08-14 01:09:21 +00:00
#define int long long
2024-08-14 00:19:09 +00:00
2024-08-14 07:13:04 +00:00
const int MAX_N = 1000+5;
2024-08-14 01:09:21 +00:00
int a[MAX_N];
int n,amax=INT_MIN,ans=0;
2024-08-14 07:13:04 +00:00
unordered_map<int,long long> um;
2024-08-14 01:09:21 +00:00
int readint();
2024-08-14 00:19:09 +00:00
2024-08-14 01:09:21 +00:00
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++){
2024-08-14 07:13:04 +00:00
a[i]=readint();
2024-08-14 01:09:21 +00:00
}
2024-08-14 07:13:04 +00:00
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];
2024-08-14 01:09:21 +00:00
}
2024-08-14 07:13:04 +00:00
}
for(auto i : um){
ans+=i.second;
2024-08-14 01:09:21 +00:00
}
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;
2024-08-14 00:19:09 +00:00
}