HDU5428
来源:互联网 发布:手机淘宝评价管理哪儿 编辑:程序博客网 时间:2024/05/22 23:19
/*对于每一个数字,它有用的部分其实只有它的所有质因子(包括相等的)。求出所有数的所有质因子中最小的两个,相乘就是答案。如果所有数字的质因子个数不到两个,那么就是无解。时间复杂度O(n*sqrt(a))O(n∗sqrt(a))*/#include <map>#include <set>#include <stack>#include <queue>#include <cmath>#include <ctime>#include <vector>#include <cstdio>#include <cctype>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;#define INF 0x3f3f3f3f#define inf -0x3f3f3f3f#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define mem0(a) memset(a,0,sizeof(a))#define mem1(a) memset(a,-1,sizeof(a))#define mem(a, b) memset(a, b, sizeof(a))typedef long long ll;ll a[110];ll count1[123456];int main(){ int t; scanf("%d",&t); int n; while(t--){ scanf("%d",&n); int cnt=0; for(int i=1;i<=n;i++){ scanf("%I64d",&a[i]); /*if(a[i]!=1) count1[cnt++]=a[i]; for(int j=2;(ll)j*j<=a[i];j++){ while(a[i]%j==0){ count1[cnt++]=j; a[i]/=j; } if(a[i]!=1){ count1[cnt++]=a[i]; } }*/ //这样的话素数会插入两次 for(int j=2;(ll)j*j<=a[i];j++){ while(a[i]%j==0){ count1[cnt++]=j; a[i]/=j; } } if(a[i]!=1){ count1[cnt++]=a[i]; } } if(cnt<2){ printf("-1\n"); continue; } else{ sort(count1,count1+cnt); printf("%I64d\n",count1[0]*count1[1]); } } return 0;}
0 0
- HDU5428
- hdu5428
- hdu5428
- HDU5428------The Factor
- The Factor(hdu5428)
- HDU5428质因数分解变形式
- HDU5428 - The Factor (因式分解)
- HDU5428 The Factor【分解质因子】
- hdu5428(BestCoder Round #54 (div.2)1002题)
- BestCoder Round #54 (div.2)(hdu5427,hdu5428,hdu5429,hdu5430)
- BestCoder Round #54 (div.2) HDU5428 The Factor
- Java基础课程学习总结,使用LinkedList简单模拟队列数据结构和堆栈数据结构的实现
- ZOJ 3689 Digging DP + 贪心
- Redis--事务
- 剑指Offer第三章面试题(Java版)
- 拿什么保护你---TDW数据安全
- HDU5428
- Android 图片上传
- hdu 5427 A problem of sorting 排序
- BZOJ 题目3998: [TJOI2015]弦论(后缀自动机求排名第k的子串,可重复)
- TDW千台Spark千亿节点对相似度计算
- Linux下安装虚拟机jre-8u60-linux-x64.tar.gz
- python学习笔记12
- 欢迎使用CSDN-markdown编辑器
- Android 定时器TimerTask 简单使用