ACM hdu 1019 Least Common Multiple
in the set and n1 ... nm are the integers. All integers will be positive and lie within the range of a 32-bit integer.
2
3 5 7 15
6 4 10296 936 1287 792 1
105
10296
/***********************
简单数学题,求连续n个数的最小公倍数
**************************/
Code:
#include <iostream>
#include<string.h>
using namespace std;
int a[10000];
int gcd(int a,int b)//求最大公约数
{
int temp;
if(a<b)
{
temp = a;a = b;b = temp;
}
return (b==0)?a:gcd(b,a%b);
}
int LCM(int a,int b)//求最小公倍数
{
return a/gcd(a,b)*b; //开始写成 a*b/gcd(a,b),WA了两次,因为可能会溢出
}
int main()
{
int T,n,ans,x;
cin>>T;
while(T--)
{
//memset(a,0,sizeof(a));
ans = 1;
cin>>n>>x;
ans = LCM(ans,x);
for(int i = 0;i<n-1;i++)
{
cin>>x;
ans = LCM(ans,x);
}
cout<<ans<<endl;
} return 0;
}
ACM 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 ...
- HDU - 1019 - Least Common Multiple - 质因数分解
http://acm.hdu.edu.cn/showproblem.php?pid=1019 LCM即各数各质因数的最大值,搞个map乱弄一下就可以了. #include<bits/stdc++ ...
- 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 ...
- ACM学习历程—HDU 3092 Least common multiple(数论 && 动态规划 && 大数)
Description Partychen like to do mathematical problems. One day, when he was doing on a least common ...
- 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 ...
- 杭电1019 Least Common Multiple【求最小公倍数】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1019 解题思路:lcm(a,b)=a*b/gcd(a,b) 反思:最开始提交的时候WA,以为是溢出了, ...
随机推荐
- nyoj 37回文串
述所谓回文字符串,就是一个字符串,从左到右读和从右到左读是完全一样的,比如"aba".当然,我们给你的问题不会再简单到判断一个字符串是不是回文字符串.现在要求你,给你一个字符串,可 ...
- 将多个Sheet导入到同一个Excel文件中
实体类excel import java.util.List; /** * 功能: * 描述: * @author * @date 2015-3-19 下午5:15:48 */ public clas ...
- Python的模块,模块的使用、安装,别名,作用域等概念
所谓的模块就是将不同功能的函数分别放到不同的文件中,这样不仅有利于函数的维护,也方便了函数的调用.在Python中,一个.py文件就是一个模块(Module). 在模块的上层有一个叫做包(Packag ...
- HW4.13
public class Solution { public static void main(String[] args) { int n = 0; while(n * n * n < 120 ...
- NTP DDOS攻击
客户端系统会ping到NTP服务器来发起时间请求更换,同步通常每隔10分钟发生: 从NTP服务器发回到客户端的数据包可能比初始请求大几百倍.相比之下,通常用于放大攻击中的DNS响应被限制仅为8倍的带宽 ...
- 20169210《Linux内核原理与分析》第六周作业
这次博客分为两部分,第一部分是实验,第二部分是教材. 第一部分:实验 这周实验的内容是使用库函数API和C代码中嵌入汇编代码两种方式使用同一个系统调用,教学案例给的是time()获取系统时间的函数,我 ...
- HDU1711-----Number Sequence-----裸的KMP
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1711 题目意思: 找出b在a中的起始位置,没有则是-1 解题思路: 裸的KMP,不多说 不会KMP的话 ...
- (linux shell)第一章--小试牛刀(上)
来源:(linux shell)第一章--小试牛刀(上) 从今天開始,我们一起来学习<linux shell脚本攻略>这本书. 1.1简单介绍 shell脚本一般是一个以#!起始的文本文件 ...
- POJ 3614 Sunscreen 优先队列 贪心
题意 有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉. 而刚开始的阳光的强度非常大,奶牛都承受不住 ...
- AOP 的利器:ASM 3.0 介绍
引言 什么是 ASM ? ASM 是一个 Java 字节码操控框架.它能被用来动态生成类或者增强既有类的功能.ASM 可以直接产生二进制 class 文件,也可以在类被加载入 Java 虚拟机之前动态 ...