http://acm.hdu.edu.cn/showproblem.php?pid=1019

Least Common Multiple

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

Problem Description
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105.
 
Input
Input will consist of multiple problem instances. The first line of the input will contain a single integer indicating the number of problem instances. Each instance will consist of a single line of the form m n1 n2 n3 ... nm where m is the number of integers in the set and n1 ... nm are the integers. All integers will be positive and lie within the range of a 32-bit integer.
 
Output
For each problem instance, output a single line containing the corresponding LCM. All results will lie in the range of a 32-bit integer.
 
Sample Input
2 3 5 7 15 6 4 10296 936 1287 792 1
 
Sample Output
105 10296

  1. #include "stdio.h"
  2. long int gb(long m,long n)
  3. {
  4. if(m>&&n>)
  5. {
  6. long a,b,r;
  7. if(n>m)
  8. {
  9. r=m;
  10. m=n;
  11. n=r;
  12. }
  13. a=m;
  14. b=n;
  15. while(r!=)
  16. {
  17. r=a%b;
  18. a=b;
  19. b=r;
  20. }
  21. return m/a*n;
  22. }
  23. else
  24. return ;
  25. }
  26. int main()
  27. {
  28. int i,n,a,b,t;
  29. scanf("%d",&t);
  30. while(t--)
  31. {
  32. scanf("%d",&n);
  33. scanf("%d",&a);
  34. for(i=;i<n;i++)
  35. {
  36. scanf("%d",&b);
  37. a=gb(a,b);
  38. }
  39. printf("%d\n",a);
  40. }
  41. }
  1. #include"stdio.h"
  2. int mcm( long x, long y)
  3. {
  4. long t;
  5. while(y)
  6. {
  7. t=x%y;
  8. x=y;
  9. y=t;
  10. }
  11. return x;
  12. }
  13. int main()
  14. {
  15. long n,m;
  16. long x,y,t1;
  17. while(scanf("%lld",&n)!=EOF)
  18. {
  19. while(n--)
  20. {
  21. scanf("%ld",&m);
  22. scanf("%ld",&x);
  23.  
  24. while(--m)
  25. {
  26. scanf("%ld",&y);
  27. t1=mcm(x,y);
  28. x=x*y/t1;
  29. }
  30. printf("%ld\n",x);
  31. }
  32. }
  33. return ;
  34. }

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 - 质因数分解

    http://acm.hdu.edu.cn/showproblem.php?pid=1019 LCM即各数各质因数的最大值,搞个map乱弄一下就可以了. #include<bits/stdc++ ...

  4. HDU 1019 Least Common Multiple 数学题解

    求一组数据的最小公倍数. 先求公约数在求公倍数.利用公倍数,连续求全部数的公倍数就能够了. #include <stdio.h> int GCD(int a, int b) { retur ...

  5. HDU 1019 Least Common Multiple GCD

    解题报告:求多个数的最小公倍数,其实还是一样,只需要一个一个求就行了,先将答案初始化为1,然后让这个数依次跟其他的每个数进行求最小公倍数,最后求出来的就是所有的数的最小公倍数.也就是多次GCD. #i ...

  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 4913 Least common multiple

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

  8. HDU 3092 Least common multiple 01背包

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3092 Least common multiple Time Limit: 2000/1000 MS ...

  9. hdu 2028 Lowest Common Multiple Plus(最小公倍数)

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

  10. HDOJ 1019 Least Common Multiple(最小公倍数问题)

    Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...

随机推荐

  1. NPOI2.0

    今天在使用NPOI2.0读取上传excel文件(excel2010)时,报了一个很奇怪的错误:无效的 URI: 未能分析主机名. 在网上查找了下找到的出错情况跟这个完全不着边际,没有办法只有自己去测试 ...

  2. css reset浅谈

    我们都知道,web开发中浏览器兼容性是困扰很多开发者的一个问题.所谓兼容性问题,即不同浏览器对同一段代码有不同的解析效果.而我们的需求往往是无论用户使用何种浏览器查看我们的网站,都应该获得相同或相近的 ...

  3. 小笔记(二):php数组

    一.对于一二维数组重新组合为另一个二维数组,根据键值名称对一个二维数组进行重新组合例: /*$paramArray=array( * 'a'=>array('0'=>'1','1'=> ...

  4. jQuery登陆判断简单实现代码

    登陆判断在实际应用中还是比较常见,在客户端执行判断可以减少服务器端的负担,感兴趣的朋友可以参考下 复制代码代码如下: <script src="jquery-1.9.1.js" ...

  5. Xshell配色方案

    几个比较喜欢的Xshell配色方案,备份记录下 [Names] count=1 name0=SolarizedDark [SolarizedDark] text(bold)=839496 magent ...

  6. MySQL - “Timeout error occurred trying to start MySQL Daemon”解决方法

    前几天,网站出现Many connections的问题,进入mysql,show full processlist发现有154个进程,晕....直接service mysqld restart 但是不 ...

  7. javascript进阶——测试和打包分发

    建立一个面向对象的好的代码基础后,为了达到代码重用的目的,通过调试使用适当的测试用例进行测试尤为必要,之后就是打包分发的主题. 一.调试与测试 1.调试 Firebug:包含了错误控制台.调试器.DO ...

  8. JFreeChart入学教程

    JFreeChart入学教程 2011-08-08 14:55:19|  分类: 技术篇 |举报 |字号 订阅   JFreeChart 是一组功能强大.灵活易用的Java绘图API,使用它可以生成多 ...

  9. load-store/register-memory/register-plus-memory比较

    在理解ARM的load-store架构时,我在百度上搜索了很长时间,但是始终找不到一篇像样的中文文章.最后,在用谷歌搜索的英文网站上终于找到了一些蛛丝马迹.让我们先看一下一篇英文资料. Process ...

  10. js经验1

    1. input 获得焦点  focus(); 2.获得文档的的title _title = document.title; 3.定时检查删除dom定时器 var deleteDomInterval ...