HDU - 1019 - Least Common Multiple - 质因数分解
http://acm.hdu.edu.cn/showproblem.php?pid=1019
LCM即各数各质因数的最大值,搞个map乱弄一下就可以了。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
map<ui,ui> M;
ll _pow(ui f,ui s){
ll res=1;
while(s){
res*=f;
s--;
}
return res;
}
bool np[100005];
ui p[100005];
int ptop=0;
void init(){
np[1]=1;
for(int i=2;i<=100000;i++){
if(np[i])
;
else{
p[ptop++]=i;
for(int j=i+i;j<=100000;j+=i)
np[j]=1;
}
}
//cout<<ptop<<endl;
}
void fj(ui tmp){
if(tmp<=1){
return;
}
if(tmp<=3){
M[tmp]++;
return;
}
for(int i=0;i<ptop&&p[i]*p[i]<=tmp;i++){
//cout<<"i="<<i<<endl;
//cout<<"p[i]="<<p[i]<<endl;
int cnt=0;
while(tmp%p[i]==0){
tmp/=p[i];
cnt++;
}
if(cnt){
M[p[i]]=max(M[p[i]],(ui)cnt);
}
}
if(tmp!=1){
M[tmp]=max(M[tmp],(ui)1);
}
return;
}
int main() {
init();
int t;
scanf("%d",&t);
while(t--) {
int n;
scanf("%d",&n);
M.clear();
while(n--){
ui tmp;
scanf("%u",&tmp);
//cout<<tmp<<endl;
fj(tmp);
}
ll ans=1;
for(auto &mi:M){
ans*=_pow(mi.first,mi.second);
}
cout<<ans<<endl;
}
}
HDU - 1019 - Least Common Multiple - 质因数分解的更多相关文章
- HDU 1019 Least Common Multiple【gcd+lcm+水+多个数的lcm】
Least Common Multiple Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- ACM hdu 1019 Least Common Multiple
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
- HDU 1019 Least Common Multiple 数学题解
求一组数据的最小公倍数. 先求公约数在求公倍数.利用公倍数,连续求全部数的公倍数就能够了. #include <stdio.h> int GCD(int a, int b) { retur ...
- HDU 1019 Least Common Multiple GCD
解题报告:求多个数的最小公倍数,其实还是一样,只需要一个一个求就行了,先将答案初始化为1,然后让这个数依次跟其他的每个数进行求最小公倍数,最后求出来的就是所有的数的最小公倍数.也就是多次GCD. #i ...
- 背包系列练习及总结(hud 2602 && hdu 2844 Coins && hdu 2159 && poj 1170 Shopping Offers && hdu 3092 Least common multiple && poj 1015 Jury Compromise)
作为一个oier,以及大学acm党背包是必不可少的一部分.好久没做背包类动规了.久违地练习下-.- dd__engi的背包九讲:http://love-oriented.com/pack/ 鸣谢htt ...
- HDU 4913 Least common multiple
题目:Least common multiple 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4913 题意:有一个集合s,包含x1,x2,...,xn, ...
- HDU 3092 Least common multiple 01背包
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3092 Least common multiple Time Limit: 2000/1000 MS ...
- hdu 2028 Lowest Common Multiple Plus(最小公倍数)
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- HDOJ 1019 Least Common Multiple(最小公倍数问题)
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
随机推荐
- mysql "ON DUPLICATE KEY UPDATE" 语法
如果在INSERT语句末尾指定了ON DUPLICATE KEY UPDATE,并且插入行后会导致在一个UNIQUE索引或PRIMARY KEY中出现重复值,则在出现重复值的行执行UPDATE:如果不 ...
- Android自动折行TextView Group
package com.test.testview; import java.util.ArrayList; import android.content.Context; import androi ...
- C# GetHashCode 的实现方式
在项目中,在使用哈希表时.有时会须要Override GetHashCode. 这里给出一种普遍的做法: 版本号1:实现一个helper.传递类型T.返回这个类型的hashcode.函数逻辑非常直接, ...
- EasyDarwin开源流媒体音视频云平台遇到的奇葩问题:内网运行正常,公网流媒体不通
最近在帮助EasyDarwin的用户部署EasyNVR+EasyDarwin云平台+EasyClient方案的过程中,遇到一个问题,EasyNVR分布在用户各地区现场的内网中,EasyDarwin云平 ...
- ECMAscript 没有对该方法进行标准化,因此反对使用它。 es 日期格式化
JavaScript substr() 方法 http://www.w3school.com.cn/jsref/jsref_substr.asp 注释:substr() 的参数指定的是子串的开始位置和 ...
- Boosting AdaBoosting Algorithm
http://math.mit.edu/~rothvoss/18.304.3PM/Presentations/1-Eric-Boosting304FinalRpdf.pdf Consider MIT ...
- Activity和ListActivity的区别
http://book.51cto.com/art/201007/212051.htm
- Linux集群基础
Linux集群基础 作者:Danbo 时间:2015-7-12 集群概述 什么是集群?集群是一组协同工作的服务器实体.用以提供比单一服务实体更具扩展性和可用性的平台. 集群的分类 1.HPC(High ...
- SCOI2017 游记(AFO)
SCOI2017 游记(AFO) Day 0 上午模拟考,又tm用暴力a了一道题,心情舒畅.(要是省选也这样该有多好,2333) 晚上又去吃了什么不知名的东西,自己都忘了,总之好像很好吃的样子. Da ...
- [bzoj1002] [FJOI2007]轮状病毒轮状病毒(基尔霍夫矩阵)
Description 轮状病毒有很多变种,所有轮状病毒的变种都是从一个轮状基产生的.一个N轮状基由圆环上N个不同的基原子 和圆心处一个核原子构成的,2个原子之间的边表示这2个原子之间的信息通道.如下 ...