BC - The Factor (아 날로 그 + 소수)

13224 단어
The Factor  
 Accepts: 160
 
 Submissions: 811
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)
문제 설명
     ,FancyCoder                ,            。    ,FancyCoder                        :            (     ;  ,4 3   ,              )。             。      ,              ;       ,   -1.

입력 설명
              T \ (1 \le T \le 15)T (1T15),      。

    TTn \ (1 \le n \le 100)n (1n100).

    nn    a_1, \ldots, a_n \ (1 \le a_1, \ldots ,a_n \le 2\times 10^9)a1,,an (1a1,,an2×109),       。

출력 설명
  TT TT

입력 샘플
2
3
1 2 3
5
6 6 6 6 6

출력 샘플
6
4
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <algorithm>
using namespace std;


#define pb push_back
#define mp make_pair
#define fillchar(a, x) memset(a, x, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(a))
#define S_queue<P> priority_queue<P, vector<P>,greater<P> >


typedef long long LL;
typedef pair<int, string > PII;
typedef unsigned long long uLL;
template<typename T>
void print(const T* p,const T* q, string Gap = " ") {
    int d = p < q ? 1 : -1;
    while(p != q) {
        cout << *p;
        p += d;
        if(p != q) cout << Gap;
    }
    cout << endl;
}
template<typename T>
void print(const T &a, string bes = "") {
    int len = bes.length();
    if(len >= 2)cout << bes[0] << a << bes[1] << endl;
    else cout << a << endl;
}

const int INF = 0x3f3f3f3f;
const int MAXM = 1e2 + 5;
const int MAXN = 1e6 +5;
int T, n, cnt;
LL B[MAXN], tmp;
int main() {
    int r = 0;
    LL re = 1;
    cin >> T;
    while(T --) {
        cin >> n;
        r = 0, re = 1;
        for(int i = 0; i < n; i ++) {
            cin >> tmp;
            re *= tmp;
            for(LL j = 2; j * j <= re; j ++) {
                if(re % j == 0) {
                    while(re % j == 0) re /= j, B[r ++]= j;
                }
            }
            if(re > 1) B[r ++] = re;
            re = 1;
        }
        sort(B, B + r);
        if(r < 2) print(-1);
        else print(B[0] * B[1]);
    }
    return 0;
}

좋은 웹페이지 즐겨찾기