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 | def GCD(a,b):
if b == 0:
return a
else:
return GCD(b, a%b)
def GCD2(a,b,c):
return GCD(GCD(a,b),c)
def GCD3(a,b,c,d):
return GCD(GCD(GCD(a,b),c),d)
#최소공배수 = (A*B) / GCD
def LCM(a,b):
return (a*b) / GCD(a,b)
def LCM2(a,b,c):
return LCM(LCM(a,b),c)
gcd = GCD(24,36)
gcd2 = GCD2(24, 36, 42)
gcd3 = GCD3(24, 36, 42, 6)
print(gcd) # 12
print(gcd2) # 6
print(gcd3) # 6
lcm = LCM(24, 36)
lcm2 = LCM2(24, 36, 42)
print(lcm) # 72
print(lcm2) # 504
|
댓글
댓글 쓰기