Gym - 101810F ACM International Collegiate Programming Contest (2018)
bryce1010模板
http://codeforces.com/gym/101810
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[1000005];
int main()
{
int t,n,temp;
ll ans,maxn,minl,x;
scanf("%d",&t);
while(t--)
{
scanf("%I64d",&n);
ans=0;
maxn=0;
minl=1e9;
memset(a,0,sizeof(a));
for(int i=0;i<n;i++)
{
scanf("%I64d",&x);
a[x]++;
maxn=max(maxn,x);
minl=min(minl,x);
}
for(ll i=minl;i<=maxn;i++)
{
if(a[i]==0)
continue;
for(ll j=2*i;j<=maxn;j+=i)
{
if(a[j]!=0)
{
a[i]+=a[j];
a[j]=0;
}
}
ans+=a[i]*i;
}
printf("%I64d\n",ans);
}
return 0;
}