The Factor
The Factor
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1274 Accepted Submission(s): 403
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.
4
题意:给一数组。求数列的乘积的最小的满足条件的因子,该因子含有两个以上因子(包括自身。
解题思路:对数列中的每一个数,找出两个最小素数因子。然后对这些质数因子排序,最小的两个数乘积便是满足条件的因子。
intention:数比较大,long long。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm> using namespace std; #define N 100000 //N*N > 10的9次方。素数表在N 以内就行。 long long b[N], num[N];
int cnt = ; void prim()
{
int a[N] = {};
for(int i = ; i < N; i++)
{
if(!a[i])
{
b[cnt++] = i;
for(int j = i+i; j < N; j+=i)
a[j] = ;
}
}
} int main()
{
int t, n;
long long d;
prim();
scanf("%d", &t);
while(t--)
{
int k = ; scanf("%d", &n);
while(n--)
{
scanf("%I64d", &d);
int q = ;
for(int i = ; i < cnt && b[i]<=d && q < ; i++) // i<cnt ,如果i> cnt,然而b[i]还是比d小,就会出现除数是0的情况……
{
while(d % b[i] == )
{
q++;
d /= b[i];
num[k++] = b[i];
if(q >= )
break;
}
} if(d != )
num[k++] = d; // 素数表在N范围内,数据范围内的素数超过N,so,剩下的d如果不是1的话,可能是超过N的素数,例如 两个素数乘积2*10016959=20033918.所以10016959要存数组num中 }
sort(num, num+k);
if(k < )
printf("-1\n");
else
printf("%I64d\n", num[]*num[]);
}
return ;
}
思维严谨……
The Factor的更多相关文章
- Leetcode 254. Factor Combinations
Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a func ...
- POJ3048 Max Factor
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...
- Factor Combinations
Factor Combinations Problem: Numbers can be regarded as product of its factors. For example, 8 = 2 x ...
- LeetCode Factor Combinations
原题链接在这里:https://leetcode.com/problems/factor-combinations/ 题目: Numbers can be regarded as product of ...
- Cognition math based on Factor Space (2016.05)
Cognition math based on Factor Space Wang P Z1, Ouyang H2, Zhong Y X3, He H C4 1Intelligence Enginee ...
- SAP中的Currency Converting Factor
ABAP编程中,有个概念很重要,即Currency Converting Factor(货币转换因子).可能很多ABAP初学者都不知道这是什么东西,这里我们就简单探讨下. 1. 什么是货币转换因子 在 ...
- Andrew Ng机器学习公开课笔记 – Factor Analysis
网易公开课,第13,14课 notes,9 本质上因子分析是一种降维算法 参考,http://www.douban.com/note/225942377/,浅谈主成分分析和因子分析 把大量的原始变量, ...
- 集群因子(Clustering Factor)
clustering factor是CBO使用的统计信息,用来衡量一个表中的列是否是规则排序存放的. 在通过索引访问表的时候,被用来作为代价评估的指示器.扫描索引的时候,clustering fact ...
- BC水题--The Factor(质因分解)
网址:http://acm.hdu.edu.cn/showproblem.php?pid=5428 roblem Description There is a sequence of n positi ...
- Approaching the Fun Factor in Game Design
I recently did some research on this and talked to Dr. Clayton Lewis (computer Scientist in Residenc ...
随机推荐
- Navicat Premium for Mac 非官方版不能启动的解决方案
Ps:这篇有点杂记的感觉,就说点废话也没什么影响.废话主要有两点: 1.建议读者也开始写博客,为什么呢?其实我也没有这种写作的习惯,我最开始写博客的时候,感觉我写的东西网上都有,需要的时候找一下肯定能 ...
- Linux - 创建交换分区 swap
购买的 1GB 内存的 Linux 小机器,在编译安装 PHP 的时候内存捉急,只好开启 swap 交换分区来增大内存. [root@VM_139_38_centos php-7.2.12]# cat ...
- create-react-app 创建react应用环境变量(env)配置
参考:https://facebook.github.io/create-react-app/docs/adding-custom-environment-variables What other . ...
- vue组件父与子通信-登录窗口
一.组件间通信(父组件 --> 子组件)步骤:①父组件在调用子组件 传值 <child-component myValue="123"> </chi ...
- 精灵图和base64如何选择
Css Sprites: 介绍: Css Sprites(雪碧图或css精灵),是网页图片处理的一种方式,它允许你将一个页面涉及到的所有零星图片都包含到一张大图中去,这样一来,当访问该页面时,载入的图 ...
- Spring Boot系列(四) Spring Boot 之验证
这节没有高深的东西, 但有一些学习思路值得借鉴. JSR 303 (Bean Validation) Maven依赖 <dependency> <groupId>org.spr ...
- 如何搭建Vue环境?
搭建vue的开发环境: https://cn.vuejs.org/v2/guide/installation.html 1. 必须要安装nodejs cnpm 下载包的速度更快一些. 地址: ...
- Win10不能远程其他远程计算机的解决办法
Win10不能远程其他远程计算机的解决办法 转自: https://blog.csdn.net/qq_38197830/article/details/69488236 首先打开控制面板——> ...
- 从零开始学编程_第A001期_C语言HelloWorld详解
emmm,这是我的第一篇博客. 作为一个软件工程专业的学生,我希望自己能在编程方面有不错的成就,我们老师告诉我们学编程就要写博客,在写博客的过程中不断成长,结交朋友,所以我就开始尝试写专业相关的博客. ...
- opencv中画圆circle函数和椭圆ellipse函数
1. void ellipse(InputOutputArray img, Point center, Size axes, double angle, double startAngle, ...