HDU 5428 the Factor for quality factor

Source: Internet
Author: User


The Factor Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 1827 Accepted Submission (s): 551


Problem Description There is a sequence of n positive integers. Fancycoder is addicted to learn their product, but the this product could be extremely huge! However, it's lucky that fancycoder only needs to find out one factor of this huge product:the smallest factor that cont Ains more than 2 factors (including itself; i.e. 4 have 3 factors so, it is a qualified factor). You need to find it out and print it. As we know, there may be none of the 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 is and both lines:

1. The first line contains one integer denoting the value of N (1≤n≤100).

2. The second line contains n integers a1,..., an (1≤a1,..., an≤2x109), 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)


The product of a minimum of two mass factors can be

<span style= "font-family:arial, Helvetica, Sans-serif;" > #include <iostream></span> #include <cstdio>
#include <map>
using namespace std;
#define LL long
ll inf = 100000000007LL;
int main () {
    int t,n;
    scanf ("%d", &t);
    while (t--) {
        scanf ("%d", &n);
        ll u;
        ll X1=inf,x2=inf;
        for (int j = 0;j < N; j + +) {
            scanf ("%lld", &u);
            for (ll i = 2;i * i <= u; i++) {while
                (u% i = = 0) {
                    if (i < x1) x2 = x1, x1 = i;
                    else if (i < x2) x2 = i;
                    u/= i;
                }
            }
            if (U = 1) {
                if (U < x1) x2 = x1, x1 = u;
                else if (U < x2) x2 = u;
            }
        }
        if (x2 = = inf) printf (" -1\n");
        else printf ("%lld\n", x1*x2);
    }
    return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.