Result: Accepted
Time: 62ms
Memory: 2540kB
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
int comp(const void *p,const void *q){
return (*(int *)q-*(int *)p);
}
int main(){
long long n,i,j,a[100001]={0},pass,z=0,count;
scanf("%lld",&n);
for(i=0;i<n;i++){
scanf("%lld",&a[i]);
}
qsort(a,n,sizeof(long long),comp);
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
count=0;
if(a[i]%a[j]!=0){
z=a[i]+a[j];
count=1;
break;
}
}
if(count==1)
break;
}
if(z<a[0])
z=a[0];
for(i=0;i<n;i++){
count=0;
if(a[i]==1){
count++;
}
}
if(count==n-1)
printf("%d\n",z+1);
else
printf("%d\n",z);
}