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 ...
随机推荐
- mac, ios 模拟器
genymotion 最好的android 硬件模拟器. 可多开,可gps定位,可模拟重力系统,可模拟磁场系统,模拟器海拔高度. 甚至可以模拟sd卡. 直接就等于真机. virtualbox 最好的 ...
- MVC 源码系列之控制器执行(二)
## 控制器的执行 上一节说道Controller中的ActionInvoker.InvokeAction public virtual bool InvokeAction(ControllerCon ...
- 升级到mysql5.7无法启动问题解决
漏洞扫描,老项目升级到5.7位成功,启动发现报错:unknown option log_error 线备份my.cnf配置文件, 猜测应该是写法有问题,先把log_error 改成log #log_ ...
- Newtonsoft.Json源码中的C#预处理指令
cs文件中包含以指令: #if !(NET35 || NET20 || PORTABLE40) 记事本打开[Newtonsoft.Json.Net20.csproj]可看到以下代码: <Defi ...
- Java ——对象 类 方法重载 构造方法 封装 内部类
本节重点思维导图 快捷键 生成代码:alt+shift+s 提取变量:alt+shift+L 快速复制行:alt+ctrl+向上或向下的箭头 删除行:ctrl+d 类:对同一种事物共同属性和行为的抽象 ...
- 应用安全 - 工具使用 - Nmap
TCP端口扫描类型 TCP connect扫描 三次握手完成/全连接/速度慢/易被检测到 TCP SYN扫描 半开扫描/发送SYN包启动TCP会话 TCP FIN扫描 半开扫描/发送SYN包启动TCP ...
- linux系统系统调优之----内核优化
主要是指在Linux系统中针对服务应用而进行的系统内核参数调整,优化没有的标准, 根据实际需求优化才是最合适的. 1)编辑内核配置文件 2)参数及简单说明 3)生效配置 1)编辑内核配置文件 vim ...
- Maven依赖项Scope属性设置含义
Idea的File->Project Structure->左侧Modules: 选择自己的项目如图: 每个依赖项的Scope选项进行该jar包的相关操作设置,默认为compile,根据需 ...
- 基本数据类型间的运算(不包括boolean)
一 基本数据类型的间的运算 (不包括boolean) 1.自动类型提升 : 小容量的变量和大容量的变量做运算结果用大容量的变量的类型来接收. byte , short , char -> in ...
- Codeforces 916E(思维+dfs序+线段树+LCA)
题面 传送门 题目大意:给定初始根节点为1的树,有3种操作 1.把根节点更换为r 2.将包含u,v的节点的最小子树(即lca(u,v)的子树)所有节点的值+x 3.查询v及其子树的值之和 分析 看到批 ...