PS/Programmers Python
프로그래머스(파이썬) - N개의 최소공배수
zpqmdh
2022. 12. 27. 14:17
https://school.programmers.co.kr/learn/courses/30/lessons/12953
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
import math
def lcm(a, b):
return (a * b) // math.gcd(a,b)
def solution(arr):
answer = arr[0]
for i in range(1, len(arr)):
answer = lcm(answer, arr[i])
return answer
math library에 lcm 함수를 지원하는 줄 알았는데 없었다..?
그래서 내가 만들어줬음
arr 배열 하나씩 돌면서 그 두 수의 최소공배수를 구해서 answer에 저장하는 방식
쉽다!