Lowest Common Multiple Plus

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 34980    Accepted Submission(s): 14272

Problem Description
求n个数的最小公倍数。
 
Input
输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。
 
Output
为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。
 
Sample Input
2 4 6
3 2 5 7
 
Sample Output
12
70
 
Author
lcy
 
Source
 
PS:欧几里得算法gcd
 
 
 #include<iostream>
#include<stdio.h>
using namespace std;
typedef __int64 inta;
inta gcd(inta a,inta b)
{
if(b==)
return a;
return gcd(b,a%b);
}
inta lcm(inta a,inta b)
{
return a*b/gcd(a,b);
}
int main()
{
int n;
while(cin >> n)
{
__int64 a;
__int64 vis=;
while(n--)
{
scanf("%I64d",&a);
vis = lcm(vis,a);
}
printf("%I64d\n",vis);
}
return ;
}

hdu 2028 Lowest Common Multiple Plus(最小公倍数)的更多相关文章

  1. HDU 2028 Lowest Common Multiple Plus

    http://acm.hdu.edu.cn/showproblem.php?pid=2028 Problem Description 求n个数的最小公倍数.   Input 输入包含多个测试实例,每个 ...

  2. #2028 Lowest Common Multiple Plus

    http://acm.hdu.edu.cn/showproblem.php?pid=2028 应该是比较简单的一道题啊...求输入的数的最小公倍数. 先用百度来的(老师教的已经不知道跑哪去了)辗转相除 ...

  3. 杭电 2028 ( Lowest Common Multiple Plus )

    链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2028 题目要求:就是求最大公倍数,我百度了一下,最好实现的算法就是:       公式法 由于 ...

  4. 最大公约数最小公倍数 (例:HDU2028 Lowest Common Multiple Plus)

    也称欧几里得算法 原理: gcd(a,b)=gcd(b,a mod b) 边界条件为 gcd(a,0)=a; 其中mod 为求余 故辗转相除法可简单的表示为: int gcd(int a, int b ...

  5. Lowest Common Multiple Plus

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

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

  7. HDU - 1019-Least Common Multiple(求最小公倍数(gcd))

    The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...

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

  9. HDU 4913 Least common multiple

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

随机推荐

  1. IOS-UI-UIDynamic(一)

    UIDynamic是从iOS7开始引入的技术 属于UIkit框架 可以模拟显示生活中的物理现象 如碰撞 抖动 摆动等 一. 使用UIDynamic步骤: 1.创建一个动力效果器UIDynamicAni ...

  2. 我的博客已搬迁到http://www.lsworks.net

    我的博客已搬迁到http://www.lsworks.net

  3. android 数据库的创建

    主java package com.itheima.createdatabase; import android.app.Activity; import android.content.Contex ...

  4. class不想被复制的两个做法

    1,当一个class不想被复制的时候,可以将copy构造函数和copy assignment操作符声明为private.(只声明不定义,因此可以不指定函数参数) 2,或者,继承一个专门为了阻止copy ...

  5. myeclipse 的 working set

    想必大家的myeclipse会有很多工程看的和不方便,那么怎么让它看的简洁一点呢,使用working set 会让你的目录看起来没有那么的多. 首先是怎么创建 working set  ,在新建时选择 ...

  6. Spring Cloud OAuth

    In this blog post we will create a secure API for external access, using OAuth 2.0, to the microserv ...

  7. 修改ECSHOP注册只需要email,并且使用email作为账号

    现在很多主流的电商网站都直接用email作为会员账号,好处是省得用户既要想一个用户名,又要填邮箱,邮箱对于电商网站的重要性不用多提,因此用email作为会员的唯一标识是很合理的做法,本文给出针对ECS ...

  8. 抄书(UVa714)

    Description   Before the invention of book-printing, it was very hard to make a copy of a book. All ...

  9. PDF ITextSharp

    示例源码 //Document:(文档)生成pdf必备的一个对象,生成一个Document示例 Document document = new Document(PageSize.A4, 30, 30 ...

  10. install window7

    install window7 http://www.zhujixc.com/win7home/http://jingyan.baidu.com/album/5bbb5a1b3e301713eba17 ...