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 ...
随机推荐
- ubuntu环境eclipse配置
ubuntu环境eclipse配置 首先下载Eclipse和JDK: 然后将上边两个压缩包解压到安装文件夹(如;/home/linux/softwares/java).然后配置/etc/profile ...
- 安装protobuf可能遇到的问题
下载protobuf-2.3.0: http://protobuf.googlecode.com/files/protobuf-2.3.0.zip http://code.google.com/ ...
- 关于erlang中的timer:tc/3
timer:tc/3对于统计函数运行时间是个很不错的函数, 截图timer:tc/1,tc/2,tc/3的API: 拿斐波那契数列入手做个讲解: -module(fib). -export([fib/ ...
- 【BZOJ2161】布娃娃 扫描线+线段树
[BZOJ2161]布娃娃 Description 小时候的雨荨非常听话,是父母眼中的好孩子.在学校是老师的左右手,同学的好榜样.后来她成为艾利斯顿第二代考神,这和小时候培养的良好素质是分不开的.雨荨 ...
- c# 委托 Predicate的使用示例
一.说明 委托Predicate 可以有参数(比如下面的示例),也可以不带参数,委托Predicate是返回固定值bool值的委托 二.示例代码(控制台程序) using System; using ...
- kernel.panic
sysctl -a kernel.panic = 0kernel.panic_on_io_nmi = 0kernel.panic_on_oops = 1kernel.panic_on_stackove ...
- 2018年东北农业大学春季校赛 B wyh的矩阵【规律】
题目链接 https://www.nowcoder.com/acm/contest/93/B 思路 先加入 中间的那行 和中间的那列 再减去 最中间那个数 因为它 加了两次 然后逐行往下加 会发现是一 ...
- Java JSON数据创建和读取
Java json数据创建 package com.JavaTest; import com.google.gson.JsonArray; import com.google.gson.JsonOb ...
- YUV420数据和字符信息如何利用滤镜方法进行编码?
YUV420数据和字符信息如何利用滤镜方法进行编码?我希望用ffmpeg中的filter方法,把YUV420数据和字符信息一起编码,该怎么办呢? 本人目前只实现了把yuv420的数据进行h.264的编 ...
- 从ffmpeg filter里出来的数据直接送给avcodec_encode_audio2编码,写文件有错。
http://hi.baidu.com/mingyuejingque/item/78e71aff57ae9ec5a835a2e4 感谢mingyuejingque st = avformat_new_ ...