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

    mysql记录总条数 $sql3 = "select * from inviter where tuijianren = '$session' "; $res3 = mysql_q ...

  2. Struts2实例详解(转载)

    Struts2(上) 一.        经典的MVC模式 二.        Struts1.x对MVC的实现 三.        Struts1.x的主要组件和作用 组件 作用 ActionSer ...

  3. 不为客户连接创建子进程的并发回射服务器( poll实现 )

    前言 在上文中,我使用select函数实现了不为客户连接创建子进程的并发回射服务器( 点此进入 ).但其中有个细节确实有点麻烦,那就是还得设置一个client数组用来标记select监听描述符集中被设 ...

  4. left outer join preserving unmatched rows from the first table

    https://docs.oracle.com/javadb/10.8.3.0/ref/rrefsqlj18922.html INNER JOIN operation Specifies a join ...

  5. 有关 java 不定参数

    不定参数实际为数组参数的一种写法而已,本质上与数组参数完全相同 //1.数组参数函数 public static int sum(int[] values) { } //2.不定参数函数 不定参数只能 ...

  6. ArcGIS服务器的feature图层限制

    今天遇到了esri.layers.FeatureLayer发布一个宗地图层,里面有些数据未显示,导致数据显示不全,原来是服务中数据返回参数限制. ArcGIS的feature图层(在JavaScrip ...

  7. Codeforces Round #371 (Div. 2) C. Sonya and Queries —— 二进制压缩

    题目链接:http://codeforces.com/contest/714/problem/C C. Sonya and Queries time limit per test 1 second m ...

  8. APP测试走过的那些坑

    我现在的工作有一大部分也是app测试,虽然自己是app开发出身,但是在测试上还是跌入了很多大坑,毕竟二者还是有很大不同,所处的角度也是不一样的.而开发转测试中,我认为较难的也是一个角度的转换,以一个开 ...

  9. ckplayer 中的style.swf 中的 style.xml 中的修改方法

    style.swf ---- > style.zip ---- > 解压成文件夹 ---- > 打开style.xml ---- > 修改 最重要的是修改保存style.xml ...

  10. C语言中的排序算法--冒泡排序,选择排序,希尔排序

    冒泡排序(Bubble Sort,台湾译为:泡沫排序或气泡排序)是一种简单的排序算法.它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来.走访数列的工作是重复地进行直到没 ...