#include #include #include #include #include #include #define ll long long using namespace std; //**************************************************************** // Miller_Rabin 算法进行素数测试 //速度快,而且可以判断 <2^63的数 //**************************************************************** const int S=20;//随机算法判定次数,S越大,判错概率越小 ll i,j,k,l,m,n; //计算 (a*b)%c. a,b都是ll的数,直接相乘可能溢出的 // a,b,c <2^63 ll mult_mod(ll a,ll b,ll c) { a%=c; b%=c; ll ret=0; while(b) { if(b&1){ret+=a;ret%=c;} a<<=1; if(a>=c)a%=c; b>>=1; } return ret; } //计算 x^n %c ll pow_mod(ll x,ll n,ll mod)//x^n%c { if(n==1)return x%mod; x%=mod; ll tmp=x; ll ret=1; while(n) { if(n&1) ret=mult_mod(ret,tmp,mod); tmp=mult_mod(tmp,tmp,mod); n>>=1; } return ret; } //以a为基,n-1=x*2^t a^(n-1)=1(mod n) 验证n是不是合数 //一定是合数返回true,不一定返回false bool check(ll a,ll n,ll x,ll t) { ll ret=pow_mod(a,x,n); ll last=ret; for(int i=1;i<=t;i++) { ret=mult_mod(ret,ret,n); if(ret==1&&last!=1&&last!=n-1) return true;//合数 last=ret; } if(ret!=1) return true; return false; } // Miller_Rabin()算法素数判定 //是素数返回true.(可能是伪素数,但概率极小) //合数返回false; bool Miller_Rabin(ll n) { if(n<2)return false; if(n==2)return true; if((n&1)==0) return false;//偶数 ll x=n-1; ll t=0; while((x&1)==0){x>>=1;t++;} for(int i=0;i=n)p=Pollard_rho(p,rand()%(n-1)+1); findfac(p); findfac(n/p); } int main() { //srand(time(NULL));//需要time.h头文件//POJ上G++不能加这句话 scanf("%I64d",&n); for (i=1;i<=n;i++) { scanf("%I64d",&m); tol=0; for (j=1;j<=m;j++) { scanf("%I64d",&l); if (l==1) continue; findfac(l); } if (tol<=1) { printf("-1\n"); continue; } sort(factor,factor+tol); printf("%I64d\n",factor[0]*factor[1]); } /* while(scanf("%I64d",&n)!=EOF) { tol=0; findfac(n); for(int i=0;i