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 ...
随机推荐
- 1.关于狗书《Flask Web开发 基于Python的web开发应用实战》身份验证的改进
在我学习用户身份验证的时候,我发现这里有个小弊端,在用户注册完成后想要验证邮箱的时候,点击邮箱中的网址进行验证,此时还要登陆,这及其不符合我们的习惯.一般情况下我们只需要点击网址就可以验证成功并且进入 ...
- pandas 入门(2)
from pandas import Series, DataFrame, Index import numpy as np from numpy import nan as NA obj = Ser ...
- 全球编程语言薪资排行榜,Java竟然垫底!!!
近日,Stack Overflow 发布了 2019 年度开发者调查报告,这次调查有来自全球的几乎将近 90000 名开发者参与,是对世界各地开发人员进行的规模最大,最全面的调查. 这次调查报告中总结 ...
- Java学习day10-面向对象特征之一:封装和隐藏
一.包package和引用import 1.关键字package package语句作为Java源文件的第一条语句,指明该文件中定义的类所在的包(若缺省该语句,则指定为无名包).包的存在是为了区别同名 ...
- 嵌入式软件工程师C语言经典笔试1
一. 预处理器(Preprocessor) 1.1. 用预处理指令#define 声明一个常数,用以表明1年中有多少秒(忽略闰年问题) #define SECONDS_PER_YEAR (60 * 6 ...
- BZOJ4990 (LCS转LIS)
题面 https://www.lydsy.com/JudgeOnline/problem.php?id=4990 分析 首先可以看出一个简单的DP dp[i][j]表示序列a前i个与序列b前j个连线数 ...
- select,poll 和 epoll ??
其实所有的 I/O 都是轮询的方法,只不过实现的层面不同罢了. 其中 tornado 使用的就是 epoll 的. selec,poll 和 epoll 区别总结 基本上 select 有 3 个缺点 ...
- Python的魔法方法??
就是可以给你的类增加魔力的特殊方法,如果你的对象实现 (重载)了这些方法中的某一个,那么这个方法就会在特殊的情况下被 Python 所调用,你可以定义自己想要的行为,而这一切都是自动发生的. __in ...
- 问题 C: 序列交换
问题 C: 序列交换 时间限制: 1 Sec 内存限制: 128 MB提交: 914 解决: 48[提交] [状态] [命题人:jsu_admin] 题目描述 给一个 1 到 n 的排列,每次可以 ...
- 20191119PHP.class类练习
<?phpclass person{ public $name; private $age; public $sex; const WOMAN=0; const MAN=1; function ...