Result: Accepted
Time: 70ms
Memory: 2108kB
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<string.h>
#include<cstring>
using namespace std;
int c[100010];
inline bool comp(int a,int b)
{
return a > b;
}
inline int Gcd(int n,int m)
{
int r;
if(n < m)
{
r = n;
n = m;
m = r;
}
while(n % m != 0)
{
r = n % m;
n = m;
m = r;
}
return m;
}
int main(void)
{
int n,i,j,k,ans,zz;
while(~scanf("%d",&n))
{
for(i = 0;i < n;i++)
{
scanf("%d",c + i);
}
sort(c,c + n,comp);
zz = c[0];
for(i = 0;i < n;i++)
{
if(i == 0)
{
ans = c[0];
}
else
{
ans = Gcd(ans,c[i]);
}
if(ans == 1)
{
if(i == 0)
{
zz = c[i];
}
else
{
zz = c[0] + c[i];
}
break;
}
}
printf("%d\n",zz);
}
return 0;
}