We guessed some integer number x. You are given a list of almost all its divisors. Almost all means that there are all divisors except 1 and x in the list.
Your task is to find the minimum possible integer x that can be the guessed number, or say that the input data is contradictory and it is impossible to find such number.
You have to answer t independent queries.
Input
The first line of the input contains one integer t (1≤t≤25) — the number of queries. Then t queries follow.
The first line of the query contains one integer n (1≤n≤300) — the number of divisors in the list.
The second line of the query contains n integers d1,d2,…,dn (2≤di≤106), where di is the i-th divisor of the guessed number. It is guaranteed that all values di are distinct.
Output
For each query print the answer to it.
If the input data in the query is contradictory and it is impossible to find such number x that the given list of divisors is the list of almost all its divisors, print -1. Otherwise print the minimum possible x.
Example
input
2
8
8 2 12 6 4 24 16 3
1
2
output
48
4
求一个数n因子的个数f(n)是一个积性函数,如果n可以表示为
n=x1p1+x2p2+x3p3+...+xmpmn=x1^{p1}+x2^{p2}+x3^{p3}+...+xm^{pm}n=x1p1+x2p2+x3p3+...+xmpm(其中x1,x2…为n的质因子)
则:
f(n)=(p1+1)∗(p2+1)∗...∗(pm+1)f(n)=(p1+1)* (p2+1)*... *(pm+1)f(n)=(p1+1)∗(p2+1)∗...∗(pm+1)
由此用质因子分解算法即可求出f(n);
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=350;
int N,t;
ll a[maxn];
int f(ll n)//求因子个数(包含1和n本身)
{
int sum=1;
for(ll i=2;i*i<=n;i++)
{
if(n%i==0)
{
int p=0;
while(n%i==0){
n/=i;
p++;
}
sum*=(p+1);
}
}
if(n>1)sum*=2;
return sum;
}
int main()
{
ios::sync_with_stdio(0);
cin>>t;
while(t--)
{
ll ans=0;
cin>>N;
for(int i=0;i<N;i++)
cin>>a[i];
sort(a,a+N);
ans=a[0]*a[N-1];
int f=0,p=-1;
for(int i=0;i<N;i++)
{
if(ans%a[i]!=0){
f=1;break;
}
}
if(f==1)cout<<p<<endl;
else {
if(f(ans)==N+2)cout<<ans<<endl;
else cout<<p<<endl;
}
}
return 0;
}