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 ...
随机推荐
- js 实现两个小数的相乘、相除功能
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- JSP不支持EL表达式的解决方案
EL的全称是Expression Language.1.在默认情况下,Servlet 2.3 / JSP 1.2是不支持EL表达式的,而Servlet 2.4 / JSP 2.0支持. servlet ...
- PYTHON2.7之前需要独立安装pip
如果python2版本是>=2.7.9, python3版本是>=3.4, pip已将一起随python安装成功了. 对于Python 2.6,你需要更旧setuptools.适用于Pyt ...
- node.js多版本管理 nvm
安装nvm 1.nvm压缩包下载地址 https://github.com/coreybutler/nvm-windows/releases 注意:Windows用户下载nvm-setup.zip 2 ...
- Netty编码的艺术
Netty 编码器原理和数据输出: Netty 默认提供了丰富的编解码框架供用户集成使用,我们只对较常用的Java 序列化编码器进行讲解.其它的编码器,实现方式大同小异.其实编码器和解码器比较类似, ...
- Java中的常用类:包装类、String、StringBuffer、StringBuilder、Math、System、Arrays、BigInteger、BigDecimal、Data、Calendar
一.包装类 √ 二.String类 ★ 三.StringBuffer和StringBuilder类 ★ 四.Math类 五.System类 六.Arrays类 七.BigInteger类和BigDec ...
- Qt5 对xml文件常用的操作(读写,增删改查)
转自:https://blog.csdn.net/hpu11/article/details/80227093 项目配置 pro文件里面添加QT+=xml include <QtXml>, ...
- python爬虫相关安装与应用
1.mysql数据库用于存储大量数据. 2.Navicat for MySQL以图形和表格等形式管理数据库工具. 3.编程语言python3与环境配置 4.pythcharm集成开发环境(社区版)不需 ...
- ES6精解:变量的解构赋值
1.数组的解构赋值 我们知道以前我们给一个变量赋值要这样如下: let a = 1; let b = 2; let c = 3; 但是ES6出来之后,我们可以这样: let [a, b, c] = [ ...
- Flask 中请求钩子的理解和应用?
请求钩子是通过装饰器的形式实现的,支持以下四种:1,before_first_request 在处理第一个请求前运行2,before_request:在每次请求前运行3,after_request:如 ...