62048 | 멀쩡한 사각형
https://programmers.co.kr/learn/courses/30/lessons/62048


작성 코드
def gcd(a: int, b: int) -> int:
a, b = max(a, b), min(a, b)
while b != 0:
a, b = b, a % b
return a
def solution(w: int, h: int) -> int:
gcd_res = gcd(w, h)
if gcd_res == 1:
return w * h - (w + h -1)
else:
return w * h - (((w // gcd_res) + (h // gcd_res) - 1) * gcd_res)반응형
'Algorithm > programmers' 카테고리의 다른 글
| [프로그래머스] 60057 | 문자열 압축 (0) | 2022.02.18 |
|---|---|
| [프로그래머스] 43165 | 타겟 넘버 (0) | 2022.02.15 |
| [프로그래머스] 42579 | 베스트앨범 (0) | 2022.01.18 |
| [프로그래머스] 42578 | 위장 (0) | 2022.01.17 |
| [프로그래머스] 68935 | 3진법 뒤집기 (0) | 2022.01.11 |
댓글