-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP12.py
More file actions
44 lines (38 loc) · 917 Bytes
/
P12.py
File metadata and controls
44 lines (38 loc) · 917 Bytes
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
#LCM and GCD
def factors(a):
b = []
i = 2
while i < a:
if a % i == 0:
b.append(i)
i += 1
return b
def common(a,b):
comm = []
for i in a:
if i in b:
comm.append(i)
return comm
def GCD(a):
length = len(a)
for i in range(length):
if i == length-1:
return a[i]
def LCM(a,b):
greater = max(a,b)
while True:
if (greater % a == 0) and (greater % b == 0):
l = greater
return 1
greater += 1
n = int(input("Enter numbers: "))
for i in range(n):
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second numbers: "))
fac1 = factors(num1)
fac2 = factors(num2)
comm = common(fac1,fac2)
ans1 = GCD(comm)
ans2 = LCM(num1,num2)
print("GCD is: ",ans1)
print("LCM is: ",ans2)