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: 79ms
Memory: 2108kB
In contest: 1276

#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;
}