Advertisement
Programmin-in-Python

LCM and HCF

Dec 22nd, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. def divisor(n) :
  2.     T1 = ()
  3.  
  4.     for i in range(1 , n+1) :
  5.         if n%i == 0:
  6.             T1 += (i,)
  7.  
  8.     return T1
  9.  
  10. def main() :
  11.     a = int(input("Enter a number : "))
  12.     b = int(input("Enter another number : "))
  13.    
  14.     common = []
  15.  
  16.     T1 = divisor(a)
  17.     T2 = divisor(b)
  18.  
  19.     for i in T1 :
  20.         for j in T2 :
  21.             if i == j:
  22.                 common.append(i)
  23.  
  24.     hcf = max(common)
  25.     lcm = int((a*b)/hcf)
  26.    
  27.     print("Highest common factor : " , hcf)
  28.     print("Least common multiple : " , lcm)
  29.    
  30. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement