관리 메뉴

솜씨좋은장씨

[BaekJoon] 1934번 : 최소공배수 (Python) 본문

Programming/코딩 1일 1문제

[BaekJoon] 1934번 : 최소공배수 (Python)

솜씨좋은장씨 2020. 7. 6. 23:20
728x90
반응형

1일 1문제 149일차!

149일차의 문제는 최소공배수 입니다.

 

1934번: 최소공배수

두 자연수 A와 B에 대해서, A의 배수이면서 B의 배수인 자연수를 A와 B의 공배수라고 한다. 이런 공배수 중에서 가장 작은 수를 최소공배수라고 한다. 예를 들어, 6과 15의 공배수는 30, 60, 90등이 있�

www.acmicpc.net

Solution

def gcd(a, b):
    mod = a%b
    while mod > 0:
        a = b
        b = mod
        mod = a%b
    return b

def lcm(a, b):
    return a*b//gcd(a,b)

loopNum = int(input())

for i in range(loopNum):
    inputNums = input()
    inputNums = inputNums.split()
    a = int(inputNums[0])
    b = int(inputNums[1])
    print(lcm(a, b))
 

SOMJANG/CODINGTEST_PRACTICE

1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.

github.com

 

Comments