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:
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≤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
 

对于每一个数字,它有用的部分其实只有它的所有质因子(包括相等的)。求出所有数的所有质因子中最小的两个,相乘就是答案。如果所有数字的质因子个数不到两个,那么就是无解。时间复杂度

O(n*sqrt(a))O(n∗sqrt(a))。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long
multiset<ll> s;
multiset<ll>::iterator it,it1;
int main()
{
int t;
scanf("%d",&t);
while(t--){
s.clear();
ll n;
scanf("%I64d",&n);
for(ll i=;i<n;i++){
ll m;
scanf("%I64d",&m);
for(ll j=;j*j<=m;j++){
if(m%j==){
while(m%j==){
s.insert(j);
m/=j;
}
}
}
if(m>) s.insert(m);
}
ll size=s.size(); if(size<) printf("-1\n");
else{
it=s.begin();
ll ans1=(*it);
it++;
ll ans2=(*it);
printf("%I64d\n",ans1*ans2);
}
}
return ;
}

hdu 5428 The Factor(数学)的更多相关文章

  1. HDU 5428 The Factor 分解因式

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5428 The Factor  Accepts: 101  Submissions: 811  Tim ...

  2. hdu 5428 The Factor 分解质因数

    The Factor  Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/contest ...

  3. HDU 5428 The Factor

    话说这题意真的是好难懂啊,尽管搜到了中文题意,然而还是没懂,最后看到了一个题解才懂的.http://www.cnblogs.com/Apro/p/4784808.html#3470972 题意:给出n ...

  4. HDU 5428 The Factor (素因数分解)

    题意:给出n个数,问这n个数的乘积中至少有三个因子的最小因子.若不存在这样的因子,则输出 -1: 思路:求出每个数的最小的两个素因数,然后输出其中最小的两个数的乘积. 代码: #include< ...

  5. hdu 2710 Max Factor 数学(水题)

    本来是不打算贴这道水题的,自己却WA了三次.. 要考虑1的情况,1的质因子为1 思路:先打表 ,然后根据最大质因子更新结果 代码: #include<iostream> #include& ...

  6. HDU 5428:The Factor

    The Factor  Accepts: 101  Submissions: 811  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65 ...

  7. HDU 5428 分解质因数

                                                                                                   The F ...

  8. HDU 4816 Bathysphere(数学)(2013 Asia Regional Changchun)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 Problem Description The Bathysphere is a spheric ...

  9. HDU 5584 LCM Walk 数学

    LCM Walk Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5584 ...

随机推荐

  1. 分享微博,qq空间,微信

    <div class="share_class" ><div class="bdsharebuttonbox">    <a hr ...

  2. (转)iOS Wow体验 - 第六章 - 交互模型与创新的产品概念(2)

    本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第六章译文精选的第二部分,其余章节将陆续放出.上一 ...

  3. [Oracle] 使用触发器实现IP限制用户登录

    在Oracle里,不像MySQL那样方便,可以直接在用户上进行IP限制,Oracle要实现用户级别的IP限制,可以使用触发器来迂回实现,下面是一个触发器的例子: create or replace t ...

  4. OpenMp 基本

      OpenMp是由OpenMP Architecture Review Board牵头提出的,并已被广泛接受的,用于共享内存并行系统的多线程程序设计的一套指导性的编译处理方案(Compiler Di ...

  5. [计算机组成原理][实验十.R-I-J型指令CPU设计实验总结]

    总算解决一大心头之患了,比想象中容易,通宵两夜,刷完了十个实验,这个实验就是最后的了.感慨颇多.特地写篇总结. 想做一件事,就立马去做把.你会发现没那么困难,往往最大的困难,是心里的困难. 培养了HD ...

  6. iphone开发 IOS 组织架构图

    转载自 :http://blog.csdn.net/mashi321323/article/details/18267719   登录|注册     mashi321323的专栏       目录视图 ...

  7. MVC4过滤器(转)

    先来看看一个例子演示过滤器有什么用: public class AdminController : Controller { // ... instance variables and constru ...

  8. Oracle instr 及 like

    原文: http://www.cnblogs.com/crazyjava/archive/2012/10/31/2748202.html instr(string1,string2[,start_po ...

  9. String.equals()

    名称                                               说明 String.Equals(Obejecct)            确定String实例是否指 ...

  10. BestCoder Round #81 (div.2)1001

    Machine Accepts: 580 Submissions: 1890 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65 ...