The Factor

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1274    Accepted Submission(s): 403

Problem Description
There is a sequence of n positive integers. Fancycoder is addicted to learn their product, but this product may be extremely huge! However, it is lucky that FancyCoder only needs to find out one factor of this huge product: the smallest factor that contains more than 2 factors(including itself; i.e. 4 has 3 factors so that it is a qualified factor). You need to find it out and print it. As we know, there may be none of such factors; in this occasion, please print -1 instead. 
 
Input
The first line contains one integer T (1≤T≤15), which represents the number of testcases.

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. 

 
Output
Print T answers in T lines.
 
Sample Input
2
3
1 2 3
5
6 6 6 6 6
 
Sample Output
6
4
 
Source

题意:给一数组。求数列的乘积的最小的满足条件的因子,该因子含有两个以上因子(包括自身。

解题思路:对数列中的每一个数,找出两个最小素数因子。然后对这些质数因子排序,最小的两个数乘积便是满足条件的因子。

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的更多相关文章

  1. 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 ...

  2. POJ3048 Max Factor

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...

  3. Factor Combinations

    Factor Combinations Problem: Numbers can be regarded as product of its factors. For example, 8 = 2 x ...

  4. LeetCode Factor Combinations

    原题链接在这里:https://leetcode.com/problems/factor-combinations/ 题目: Numbers can be regarded as product of ...

  5. 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 ...

  6. SAP中的Currency Converting Factor

    ABAP编程中,有个概念很重要,即Currency Converting Factor(货币转换因子).可能很多ABAP初学者都不知道这是什么东西,这里我们就简单探讨下. 1. 什么是货币转换因子 在 ...

  7. Andrew Ng机器学习公开课笔记 – Factor Analysis

    网易公开课,第13,14课 notes,9 本质上因子分析是一种降维算法 参考,http://www.douban.com/note/225942377/,浅谈主成分分析和因子分析 把大量的原始变量, ...

  8. 集群因子(Clustering Factor)

    clustering factor是CBO使用的统计信息,用来衡量一个表中的列是否是规则排序存放的. 在通过索引访问表的时候,被用来作为代价评估的指示器.扫描索引的时候,clustering fact ...

  9. BC水题--The Factor(质因分解)

    网址:http://acm.hdu.edu.cn/showproblem.php?pid=5428 roblem Description There is a sequence of n positi ...

  10. 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. 【MM系列】SAP MM中的委外加工与信息记录

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP MM中的委外加工与信息记录 ...

  2. 应用安全-web安全-WebShell整理

    shellcode.aspx <%@ Page Language="C#" AutoEventWireup="true" Inherits="S ...

  3. C# DataSet转JSON

    经常会遇到系统数据交互采用JSON数据格式进行交互的,避免不必要的重复工作,记录下自己的处理方式. 获取数据集之后,通过函数对数据集信息进行整理通过.Net Framework3.5提出的JavaSc ...

  4. 从头到尾说一次 Java 垃圾回收,写得非常好!

    Java技术栈 www.javastack.cn 优秀的Java技术公众号 作者:聂晓龙(花名:率鸽),阿里巴巴高级开发工程 ⬆️ 图片来源于网络 之前上学的时候有这个一个梗,说在食堂里吃饭,吃完把餐 ...

  5. python为什么人们喜欢学习呢?

    软件的质和量. 既有量的积累也有质的区别.继承一定的前人研究基础. 基本上来说,python更加的注重可读性,一致性,可移植性,其中软件的质量也是比较的讲究的. python支持开发的高级重用机制,例 ...

  6. Python2中range 和xrange的区别??

    两者用法相同,不同的是range返回的结果是一个列表,而xrange的结果是一个生成器, 前者是直接开辟一块内存空间来保存列表,后者是边循环边使用,只有使用时才会开辟内存空间, 所以当列表很长时,使用 ...

  7. TAB切换与内容伸展闭合的结合

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 显式Mapping设置与常见参数介绍

    原文:显式Mapping设置与常见参数介绍 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/ ...

  9. Elasticsearch7.X 入门学习第七课笔记-----Mapping多字段与自定义Analyzer

    原文:Elasticsearch7.X 入门学习第七课笔记-----Mapping多字段与自定义Analyzer 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处 ...

  10. Form表单组件验证

    第一版:最基本版本 views源码 #——————————————————————form验证—————————————— from django import forms from django.f ...