游客 Signup | Login
中文 | En

2006 - 整除问题

给出n个数a1,a2…an,求出一个数T,要求T能整除n个数中的其中n-1个,但不能整除所有的n个数,如果存在多个T,输出最小的。

例如2,3,5,则输出6,因为6是2和3的最小公倍数,但不是2,3,5的最小公倍数,T还可能是10,15,75等,但是由于6最小,所以输出6.

如果T不存在,则输出-1。

Input

第一行输入n,表示n个数,1<n<=6接下来一行输入n个数,0<a1…an,ai<=15

Output

一个数,T,其中每个测试数据占一行

Examples

Input

3
2 3 5
3
10 6 15

Output

6
-1

Solution C++

#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int a[6];
    int n;
    while(scanf("%d",&n)!=EOF)
    {  int co=1;
        for(int i=0;i<n;i++)
        {
             scanf("%d",&a[i]);
             co*=a[i];
        }
        sort(a,a+n);

        int z=0;
        for(int i=a[n-2];i<co;i++)
        { int t=0;
            for(int j=0;j<n;j++)
            {
                if(i%a[j]==0)t++;
            }

            if(t==n-1)
                {z=i;break;}

        }
        if(z==0) printf("-1\n");
        else printf("%d\n",z);
    }
}

Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题