BC - The Factor(模拟题 + 素数)

47 篇文章 0 订阅
23 篇文章 0 订阅

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),表示数据组数。

接下去有TT组数据,每组数据的第一行有一个正整数n \ (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), 表示这个数列。
输出描述
输出TTTT个数表示每次询问的答案。
输入样例
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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值