Start: Jun, 28, 2019 08:42:00
2019杭州师范大学第一届程序设计竞赛新生赛
End: Jun, 28, 2019 11:42:00
Time elapsed:
Time remaining:

Problem_ID: H
Result: Accepted
Time: 70ms
Memory: 3376kB
In contest: 1276

#include<cstdio>
#include<cmath>
#include<string.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<string>
#include<stdlib.h>
using namespace std;
const int p=0x3f3f3f3f;
#define maxn 100005
long long a[maxn],b[maxn];
int n,m,k,x,y,l,r;
char s[maxn];
int gcd(int a,int b)
{
	return b==0?a:gcd(b,gcd(b,a%b));
}
int cmp(int a,int b)
{
	return a>b;
}

int main()
{
	while(~scanf("%d",&n))
	{
		for(int i=0;i<n;i++)
			scanf("%lld",&a[i]);
		sort(a,a+n,cmp);
		long long sum=a[0];
		for(int i=0;i<n/2;i++)
		{
			if(a[0]%a[i]!=0)
			{
				sum+=a[i];
				break;
			}
			else if(a[0]%a[n-1-i]!=0)
			{
				sum+=a[n-1-i];
				break;
			}
		}
		printf("%lld\n",sum);
	}
}