链接在这
Problem Description
There is a sequence of n positive integers. Fancycoder is addicted to learn their product, but this product may be extremely huge! However, it is lucky that FancyCoder only needs to find out one factor of this huge product: the smallest factor that contains more than 2 factors(including itself; i.e. 4 has 3 factors so that it is a qualified factor). You need to find it out and print it. As we know, there may be none of such factors; in this occasion, please print -1 instead.
Input
The first line contains one integer T (1≤T≤15), which represents the number of testcases.
For each testcase, there are two lines:
The first line contains one integer denoting the value of n (1≤n≤100).
The second line contains n integers a1,…,an (1≤a1,…,an≤2×109), which denote these n positive integers.
Output
Print T answers in T lines.
Sample Input
2
3
1 2 3
5
6 6 6 6 6
Sample Output
6
4
Source
BestCoder Round #54 (div.2)
有一个数列,FancyCoder沉迷于研究这个数列的乘积相关问题,但是它们的乘积往往非常大。幸运的是,FancyCoder只需要找到这个巨大乘积的最小的满足如下规则的因子:这个因子包含大于两个因子(包括它本身;比如,4有3个因子,因此它是满足这个要求的一个数)。你需要找到这个数字并输出它。但是我们知道,对于某些数可能没有这样的因子;在这样的情况下,请输出-1.
我的代码如下:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define LL long long
using namespace std;
LL a[111],b[111];
int main()
{
int T;
cin>>T;
int i,n;
while(T--)
{
cin>>n;
int signum=0;
for(i=1;i<=n;i++)
{
scanf("%ld",&a[i]);
for(int j=2;j<=sqrt(a[i]);j++)
{
if(a[i]%j==0){
b[++signum]=j;
}break;
}
if(a[i]!=1&&a[i]%2!=0||a[i]==2){
b[++signum]=a[i];
}
}
if(signum<2)
cout<<-1<<endl;
else{
sort(b+1,b+signum+1);
long long desnum=b[1]*b[2];
cout << desnum <<endl;
}
}
return 0;
}
结果一直显示Wrong Answer,研究了一天了,求大神解答