Skip to content

Commit

Permalink
solve(programmers): LV2_12953_N개의 최소공배수_py
Browse files Browse the repository at this point in the history
  • Loading branch information
gogumaC committed Apr 24, 2024
1 parent 0ca69db commit 0e11523
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/programmers/level_1/수학/N개의_최소공배수.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def solution(arr):
lcm = 1
for i in arr:
lcm = get_lcm(lcm, i)

return lcm


def get_lcm(a, b):
mul = 1
while True:
has_d = False
for i in range(2, min(a, b) + 1):
if a % i == 0 and b % i == 0:
has_d = True
mul *= i
a //= i
b //= i
break
if not has_d:
return mul * a * b

0 comments on commit 0e11523

Please sign in to comment.