地址: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的更多相关文章

  1. K - Least Common Multiple

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Descr ...

  2. [UCSD白板题] Least Common Multiple

    Problem Introduction The least common multiple of two positive integers \(a\) and \(b\) is the least ...

  3. hdu1019 Least Common Multiple

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

  4. HDOJ2028Lowest Common Multiple Plus

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

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

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

  6. 九度OJ 1056--最大公约数 1439--Least Common Multiple 【辗转相除法】

    题目地址:http://ac.jobdu.com/problem.php?pid=1056 题目描述: 输入两个正整数,求其最大公约数. 输入: 测试数据有多组,每组输入两个正整数. 输出: 对于每组 ...

  7. HDU-1019 Least Common Multiple

    http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (Java/ ...

  8. ACM hdu 1019 Least Common Multiple

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

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

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

随机推荐

  1. Visual C++ 6.0常用快捷键

    一.常用编译相关的快捷键 1.编译(单个文件)  Ctrl+F7 2.连接 F7 3.运行  Ctrl+F5 二.常用调试相关的快捷键 1.GO(全速运行)  F5 2.Stop Debuging(停 ...

  2. Razor引擎总结

    1.显示格式化小数:@(string.Format("{0:0.00}",ViewData["TradeAmount"].ToNullString()))

  3. Steam游戏黑屏与游戏直接安装方法

    黑屏原因主要是360禁止了反作弊进程,解决方法: Steam游戏目录: Steam\steamapps\common\*** 例如黎明杀机,备份时候可直接备份该目录下 Dead by Daylight ...

  4. 点击播放js

    <div class="videobox" id="videobox"> <img src="temp/pic1.jpg" ...

  5. jquery多级手风琴插件–accordion.js

    手风琴菜单一般用于下拉导航,由于外观非常简洁,使用起来跟手风琴一样可以拉伸和收缩而得名,项目中适当应用手风琴效果会给用户带来非常好的体验.本文借助jQuery插件轻松打造一个非常不错的手风琴效果的菜单 ...

  6. 设计模式之观察者(Observer)模式 代码详解

    import java.util.ArrayList; import java.util.List; /** * User: HYY * Date: 13-10-28 * Time: 下午1:34 * ...

  7. 【Xamarin挖墙脚系列:Xamarin.IOS的程序的结构】

    原文:[Xamarin挖墙脚系列:Xamarin.IOS的程序的结构] 开始熟悉Xamarin在开发IOS的结构!!!!!!! 先看官方 这个是以一个单页面的程序进行讲述的. 1 程序引用的程序集,核 ...

  8. 转:二十一、详细解析Java中抽象类和接口的区别

    转:二十一.详细解析Java中抽象类和接口的区别 http://blog.csdn.net/liujun13579/article/details/7737670 在Java语言中, abstract ...

  9. Android模拟器——Genymotion

    还在用Android原生模拟器?向你推荐一款全方位把Android原生模拟器秒成渣渣的神器:Genymotion! 需要理由? 性能卓越作为历史上最快的Android模拟器(没有之一),秒级开机关机速 ...

  10. HDOJ --- 1258

    #include<map> #include<string> #include<cstdio> #include<cstring> #include&l ...