Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create 2024-03-11-level2-12.md #102

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions _posts/2024-03-11-level2-12.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
layout: single
title: "프로그래머스 LV2 - N개의 최소공배수"
categories: CodingTest
tag: [LV2, 프로그래머스, 코딩테스트, ONE MORE TIME]
author_profile: false
sidebar:
nav: "counts"
---

[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/12953)


## 내 풀이
```python
def solution(arr):
min_gong = arr[0]
for num in arr[1:]:
for i in range(1, num+1):
if min_gong % i == 0 and num % i == 0:
max_yak = i
min_gong = min_gong * num // max_yak

return min_gong
```

## 다른 풀이
```python
def solution(arr):

    result = 1

    # arr에 대해 순회하면서 최소공배수 업데이트
    for i in arr:
        result = lcm(result, i)

    return result

# 최대공약수 구하는 함수
def gcd(x, y):

    while y:
        x, y = y, x%y

    return x

# 최소공배수 구하는 함수
def lcm(x, y):

    return x * y // gcd(x, y)
출처: https://1ets-just-do-it.tistory.com/134 [파이썬은 신이야🔥🔥🔥:티스토리]
```

### 풀이 해석
- 유클리드 호제법을 이용한 최대공약수 도출
- 두 수를 곱한 것에 최대공약수를 나눠주면 최소공배수

### 배울 점
- 유클리드 호제법의 활용
- 함수를 여러개 사용하여 호출
Loading