hdu5428
来源:互联网 发布:顺丰科技 知乎 编辑:程序博客网 时间:2024/05/22 14:49
链接:点击打开链接
题意:给出一列数,在其中可以选择任意个数的数相乘,求相乘这个数的最小合数因子
代码:
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;long long prime[500005],num[500005];int main(){ long long i,j,t,n,cur,flag,sign; long long temp[1005]; scanf("%I64d",&t); while(t--){ flag=0; scanf("%I64d",&n); for(i=0;i<n;i++){ sign=0; //因为是求一个最小的合数因子,因此只要选其中两个 scanf("%I64d",&cur); //最小质因子相乘即可 for(j=2;j*j<=cur;j++){ while(cur%j==0){ //分解质因子 temp[flag++]=j; cur/=j; } } if(cur!=1) temp[flag++]=cur; //如果是质数直接存上 } if(flag==0||flag==1) //质因子个数小于2输出-1 printf("-1\n"); else{ sort(temp,temp+flag); printf("%I64d\n",temp[0]*temp[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
- GPIO中断使用小结
- Linux Shell笔记之函数
- Freemarker自定义方法
- c语言 实现ping 功能/效果 检测当前网络是否连通
- Socket之shutdown()用法
- hdu5428
- 零基础入门Sketch
- Gabor变换
- KL散度
- 【NeatUpload】大附件上传配置文件
- Hibernate – One-to-Many example (Annotation)
- C++ 之 虚函数、虚基类与纯虚函数 浅析
- html上汉字乱码解决
- java 长整除问题