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. 计算IMEI号的校验位

    计算IMEI号的校验位 移动设备国际识别码(IMEI:International Mobile Equipment Identification Number)是差别移动设备的标志,具有唯一性,贴在手 ...

  2. mybatis学习总结(一)——简介

    基本构成 SqlSessionFactoryBuilder(构造器):它会根据配置信息或者代码来生成SqlSessionFactory(工厂接口) SqlSessionFactory:依靠工厂来生成S ...

  3. Collection of Boot Sector Formats for ISO 9660 Images

    http://bazaar.launchpad.net/~libburnia-team/libisofs/scdbackup/view/head:/doc/boot_sectors.txt Colle ...

  4. SPDY: An experimental protocol for a faster web HTTP/2

    http://www.chromium.org/spdy/spdy-whitepaper https://en.wikipedia.org/wiki/SPDY Internet protocol su ...

  5. spring4.2更好的应用事件

    1.基于注解驱动事件监听器:现在可以在一个Bean的方法上使用@EventListener注解来自动注册一个ApplicationListener来匹配方法签名. @Component public ...

  6. php遍历统计文件目录和文件

    function total($dirname, &$dirnum, &$filenum){ $dir=opendir($dirname); readdir($dir)."& ...

  7. SDUT OJ 之 1571 《人品,有没有?》 字符串的处理问题

    人品,有木有? Time Limit: 1000ms   Memory limit: 32768K  有疑问?点这里^_^ 题目描述 新一届的山东理工大学ACM网络擂台赛就要开始啦!听说晋级的选手有机 ...

  8. python把字典写入excel之一例

    直接上代码: # -*- coding: utf-8 -*- import xlsxwriter #生成excel文件 def generate_excel(expenses): workbook = ...

  9. Relative atomic mass

    Relative atomic mass Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  10. 2018值得选用的五个Linux服务器发行版

    [IT168 编译]据最新统计,目前Linux发行版约有300种,几乎都可以作为服务器系统运行.在Linux早期,几乎所有发行版都是“万能”发行版,专门的Linux服务器发行版并不火热,到21世纪初, ...