본문 바로가기

Language/Python

[Python] 최대 공약수, 최소 공배수

1. 최대 공약수

import math

n, m = map(int, input().split())

print(math.gcd(n,m))

 

2. 최소 공약수

= 두 수의 곱 / 최대 공약수

import math

n, m = map(int, input().split())

print( (n*m) / math.gcd(n,m) )