博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu_1019Least Common Multiple(最小公倍数)
阅读量:4569 次
发布时间:2019-06-08

本文共 1977 字,大约阅读时间需要 6 分钟。

太简单了。。。题目都不想贴了

 

1 //算n个数的最小公倍数 2 #include
3 #include
4 #include
5 using namespace std; 6 int gcd(int a, int b) 7 { 8 return b==0?a:gcd(b,a%b); 9 }10 int lcm(int a, int b)11 {12 return a/gcd(a,b)*b;13 }14 int main()15 {16 int T;17 scanf("%d",&T);18 while(T--)19 {20 int n;21 scanf("%d",&n);22 int tm = 1;23 int a;24 for(int i = 0; i < n; i++){25 scanf("%d",&a);26 tm = lcm(tm,a);27 }28 printf("%d\n",tm);29 }30 return 0;31 }

 

 
     
 | 
  
 

Least Common Multiple

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 45603    Accepted Submission(s): 17131
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
 
Source
 
Recommend
JGShining   |   We have carefully selected several similar problems for you:            
 
 |   |   | 
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2016 . All Rights Reserved.
: Wang Rongtao LinLe  
Total 0.000000(s) query 5, Server time : 2016-07-15 07:14:06, Gzip enabled

转载于:https://www.cnblogs.com/shanyr/p/5672283.html

你可能感兴趣的文章
为什么要配置sdk-tools/platform-toools?
查看>>
自己动手开发更好用的markdown编辑器-07(扩展语法)
查看>>
maven dependency:tree中反斜杠的含义
查看>>
队列的循环队列
查看>>
程序中的日期格式
查看>>
大众点评CAT错误总结以及解决思路
查看>>
从0开始学爬虫3之xpath的介绍和使用
查看>>
Shell成长之路
查看>>
vim下正则表达式的非贪婪匹配
查看>>
一个python的计算熵(entropy)的函数
查看>>
spring源码学习——spring整体架构和设计理念
查看>>
模拟window系统的“回收站”
查看>>
报文格式【定长报文】
查看>>
RDLC报表钻取空白页问题
查看>>
多路电梯调度的思想
查看>>
jQuery-对Select的操作
查看>>
过滤器、监听器、拦截器的区别
查看>>
为什么要进行需求分析?通常对软件系统有哪些需求?
查看>>
一些模板
查看>>
jquery和dom元素相互转换
查看>>