Result: Accepted
Time: 79ms
Memory: 2108kB
#include<bits/stdc++.h>
using namespace std;
const int maxx = 1e5+10;
int arr[maxx];
int isprime(int x)
{
int tf = 1;
int n = x/2;
for(int i = 2;i <= n;++i)
{
if(x % i == 0)
break;
}
return tf;
}
int gcd(int x,int y)
{
int z = x%y;
while(x%y != 0)
{
z = x%y;
x = y;
y = z;
}
return z;
}
int cmp(int a,int b)
{
return a > b;
}
int main()
{
int n;
scanf("%d",&n);
for(int i = 1;i <= n;++i)
scanf("%d",&arr[i]);
sort(arr+1,arr+1+n,cmp);
int eat = arr[1];
int tf = isprime(arr[1]);
// for(int i = 1;i <= n;++i)
// printf("%d ",arr[i]);
for(int i = 1;i <= n;++i)
{
for(int j = i+1;j <= n;++j)
{
if(gcd(arr[i],arr[j]) == 1)
{
int ij = arr[i]+arr[j];
if(ij > eat)
{
eat = ij;
tf = isprime(arr[i])+isprime(arr[j]);
if(tf > 0)
{
tf++;
break;
}
}
}
}
if(tf > 1)
break;
}
printf("%d\n",eat);
return 0;
}