Least Common Multiple
地址:http://www.codewars.com/kata/5259acb16021e9d8a60010af/train/python
题目:
Write a function that calculates the least common multiple of its arguments; each argument is assumed to be a non-negative integer.
代码:
def lcm2(a,b):
m = max(a,b)
n = min(a,b)
if n == 0:
return 0 while(n>1):
if m%n == 0:
return a*b/n
else:
t = n
n = m%n
m = t return a*b/n def lcm(*args):
lenA = len(args)
if lenA == 1:
return args[0]
elif lenA == 2:
return lcm2(args[0],args[1])
else:
ans = lcm2(args[0],args[1])
for i in range(2,lenA):
ans = lcm2(ans,args[i])
return ans
Least Common Multiple的更多相关文章
- K - Least Common Multiple
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Descr ...
- [UCSD白板题] Least Common Multiple
Problem Introduction The least common multiple of two positive integers \(a\) and \(b\) is the least ...
- hdu1019 Least Common Multiple
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
- HDOJ2028Lowest Common Multiple Plus
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- hdu 2028 Lowest Common Multiple Plus(最小公倍数)
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- 九度OJ 1056--最大公约数 1439--Least Common Multiple 【辗转相除法】
题目地址:http://ac.jobdu.com/problem.php?pid=1056 题目描述: 输入两个正整数,求其最大公约数. 输入: 测试数据有多组,每组输入两个正整数. 输出: 对于每组 ...
- HDU-1019 Least Common Multiple
http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (Java/ ...
- ACM hdu 1019 Least Common Multiple
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
- HDOJ 1019 Least Common Multiple(最小公倍数问题)
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
随机推荐
- 使用ajax和history.pushState无刷新改变页面URL onpopstate(转)
Javascript代码 var htmlData1 = $.ajax( { url: "/getXXXResponse", async: false }).re ...
- 从头搭建Spring MVC
1.拷贝jar文件 2.填充Web.xml 在/WEB-INF/web.xml中写入如下内容: <?xml version="1.0" encoding="UTF- ...
- MINA源码阅读之Future系
首先Future系是对某个异步操作完成的监听:即setValue()的完成情况监听:get/setValue其实是对result字段封装,由此,可以这样讲,Future系其实对于对result字段状态 ...
- HTTP状态码——对照表
ASCII码介绍: HTTP状态码(HTTP Status Code)用来表示web服务器响应客户端的HTTP状态.主要有一下5种状态类型.1xx 消息2xx 成功3xx 重定向4x ...
- RTP
RTP学习(三)RTP/RTCP/RTSP数据包格式 h264RTP打包描述的较为详细(含SDP中sps等信息的描述) UDP.TCP.RTP三种协议的总结 http://super-and-star ...
- 转:三十二、Java图形化界面设计——布局管理器之CardLayout(卡片布局)
转:http://blog.csdn.net/liujun13579/article/details/7773945 卡片布局能够让多个组件共享同一个显示空间,共享空间的组件之间的关系就像一叠牌,组件 ...
- How to: Use a Custom User Name and Password Validator
在wcf中使用自定义的用户名和密码验证方式 https://msdn.microsoft.com/en-us/library/aa702565.aspx http://www.codeproject. ...
- 【转】iOS开发者申请发布证书及真机调试图文详解
原文网址:http://www.tqcto.com/article/mobile/57822.html 打开iOS Dev Center,选择Sign in,登陆(至少99美元账号),登陆之后在网页右 ...
- SVN服务器及客户端的使用
Subversion是优秀的版本控制工具,其具体的的优点和详细介绍,这里就不再多说. 首先来下载和搭建SVN服务器. 现在Subversion已经迁移到apache网站上了,下载地址:http://s ...
- Ignatius and the Princess III
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...