Created
June 19, 2017 11:52
-
-
Save stripe-q/fe1d425fac999995109956d95ad1f3e8 to your computer and use it in GitHub Desktop.
최소공배수와 최대공약수
This file contains hidden or 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
from lcd import lcd | |
from functools import reduce | |
def main(): | |
n = reduce(lcd, range(1, 21)) | |
print(n) | |
if __name__ == '__main__': | |
main() |
This file contains hidden or 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 gcd(a, b): | |
if a < b: | |
a, b = b, a | |
if a % b == 0: | |
return b | |
return gcd(b, a % b) | |
if __name__ == '__main__': | |
x, y = [int(n) for n in input("두 수를 입력하세요:").split()[:2]] | |
g = gcd(x, y) | |
print("%d와 %d의 최대 공약수는 %d 입니다." % (x, y, g)) |
This file contains hidden or 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
from gcd import gcd | |
def lcd(a, b): | |
g = gcd(a, b) | |
x, y = a // g, b // g | |
return x * y * g | |
if __name__ == '__main__': | |
x, y = [int(n) for n in input("두 수를 입력하세요:").split()[:2]] | |
l = lcd(x, y) | |
print("%d와 %d의 최소 공배수는 %d 입니다." % (x, y, l)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment