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 - 质因数分解的更多相关文章

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

  2. ACM hdu 1019 Least Common Multiple

    Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...

  3. HDU 1019 Least Common Multiple 数学题解

    求一组数据的最小公倍数. 先求公约数在求公倍数.利用公倍数,连续求全部数的公倍数就能够了. #include <stdio.h> int GCD(int a, int b) { retur ...

  4. HDU 1019 Least Common Multiple GCD

    解题报告:求多个数的最小公倍数,其实还是一样,只需要一个一个求就行了,先将答案初始化为1,然后让这个数依次跟其他的每个数进行求最小公倍数,最后求出来的就是所有的数的最小公倍数.也就是多次GCD. #i ...

  5. 背包系列练习及总结(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 ...

  6. HDU 4913 Least common multiple

    题目:Least common multiple 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4913 题意:有一个集合s,包含x1,x2,...,xn, ...

  7. HDU 3092 Least common multiple 01背包

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3092 Least common multiple Time Limit: 2000/1000 MS ...

  8. hdu 2028 Lowest Common Multiple Plus(最小公倍数)

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  9. HDOJ 1019 Least Common Multiple(最小公倍数问题)

    Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...

随机推荐

  1. 通过串口工具下发指令的Python脚本

    前言 最近一段时间在测试物联网相关的App自动化,涉及通过串口工具给硬件设备下发指令. 使用的串口工具:SecureCRT 解决办法 通过引用Python的第三方库:serial,通过编写Python ...

  2. codeforces Looksery Cup 2015 H Degenerate Matrix

    The determinant of a matrix 2 × 2 is defined as follows: A matrix is called degenerate if its determ ...

  3. RecyclerView的那点事儿

    RecyclerView 控件简单介绍 ListView的升级版 LinearLayoutManager GridLayoutManager StaggeredGridLayoutManager 定制 ...

  4. Find out when memory leaks are a concern and how to prevent them

    Handling memory leaks in Java programs Find out when memory leaks are a concern and how to prevent t ...

  5. mongodb学习之:安全和认证

    mongodb默认是不认证的,默认没有账号,只要能连接上服务就可以对数据库进行各种操作,mongodb认为安全最好的方法就是在一个可信的环境中运行它,保证之后可信的机器才能访问它.因此需要在登录的时候 ...

  6. EF 编程经验

    http://blog.csdn.net/itmaxin/article/details/47662151 这篇文章里有一下东西可以参考,但是弟二个方法明显是不可行的,因为我做了实验直接attach ...

  7. socket 学习笔记

    #include <sys/socket.h> ---------------------------------------------------------------------- ...

  8. JQuery的extend

    jQuery.extend 函数详解 JQuery的extend扩展方法:      Jquery的扩展方法extend是我们在写插件的过程中常用的方法,该方法有一些重载原型,在此,我们一起去了解了解 ...

  9. SDUT 2402 水杯最小表面积问题

    水杯 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 天气逐渐变热了,准备考研的高童鞋打算在夏天来临之前自己动手造一个水杯,以备口 ...

  10. POJ2389 —— 高精度乘法

    直接上代码了: #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib& ...