Smallest multiple: Difference between revisions
Content added Content deleted
m (→{{header|Python}}: simplify) |
|||
Line 474: | Line 474: | ||
from functools import reduce |
from functools import reduce |
||
def lcm(a, |
def lcm(a,b): |
||
""" least common multiple """ |
""" least common multiple """ |
||
return int(abs(a |
return int(abs(a*b) / gcd(a,b)) |
||
for i in [10, 20, 200]: |
for i in [10, 20, 200]: |
||
print(i |
print(str(i) + ':', reduce(lcm, range(1, i + 1))) |
||
</lang>{{out}} |
</lang>{{out}} |
||
<pre> |
<pre> |
||
10 |
10: 2520 |
||
20 |
20: 232792560 |
||
200 |
200: 406223405488266528941807089475561526729920491439317610846106007364194068990773980214853993805940114288328203598436687354558152299530325929626578124378588043546734967334192274905429717169202850358367337285700993918963748498703256809194612087695134987729083306000942716524953600 |
||
</pre> |
</pre> |
||