Created
April 13, 2012 14:44
-
-
Save hatashiro/2377368 to your computer and use it in GitHub Desktop.
Projecteuler #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lcd(a, b): | |
if a==1 or b==1: | |
return a*b | |
a_now = a | |
b_now = b | |
denominator = 1 | |
factor = 2 | |
while True: | |
if a_now%factor and b_now%factor: | |
factor = factor + 1 | |
else: | |
if not a_now%factor: | |
a_now = a_now / factor | |
if not b_now%factor: | |
b_now = b_now / factor | |
denominator = denominator * factor | |
if a_now == 1 and b_now == 1: | |
break | |
return denominator | |
def lcd_of_1_from(int): | |
if int == 1: | |
return 1 | |
else: | |
return lcd(int, lcd_of_1_from(int-1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment