-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathN개의 최소공배수.py
52 lines (46 loc) · 911 Bytes
/
N개의 최소공배수.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'''
def gcd(a,b):
a,b=max(a,b),min(a,b)
while b > 0:
a,b=b,a%b
return a
def solution(arr):
while len(arr) !=1:
a=arr.pop()
b=arr.pop()
c=gcd(a,b)
arr.insert(0,int(a*b/c))
answer=arr[0]
return answer
'''
'''
#2020.03.04
def gcd(a,b):
if a % b == 0:
return b
return gcd(b,a%b)
def chlthrhd(arr):
if len(arr) == 1:
return arr[0]
a = arr.pop()
b = arr.pop()
chleorhd = gcd(a,b)
arr.append(a*(b // chleorhd))
return chlthrhd(arr)
def solution(arr):
return chlthrhd(arr)
'''
#2022.11.15
def get_gcd(a, b):
if b == 1:
return 1
if a % b == 0:
return b
return get_gcd(b, a%b)
def get_glm(a, b):
return a*b / get_gcd(max(a,b), min(a,b))
def solution(arr):
answer = arr.pop()
for val in arr:
answer = get_glm(answer, val)
return answer