Guest User

Untitled

a guest
Feb 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. # LCM or least common multiplier of two number is the smallest number that is divisible by both of these numbers.
  4.  
  5. import sys
  6.  
  7. def multiplier(x):
  8. i = 1
  9. while True:
  10. yield x * i
  11. i += 1
  12.  
  13. def lcm(x, y):
  14. if x < y:
  15. x, y = y, x
  16.  
  17. for i in multiplier(x):
  18. if i % y == 0:
  19. return i
  20.  
  21. if __name__ == '__main__':
  22. x = int(sys.argv[1])
  23. y = int(sys.argv[2])
  24.  
  25. if any([True for i in [x, y] if i < 0 or i == 0]):
  26. raise ValueError('both of the two numbers must be positive.')
  27.  
  28. print(lcm(x, y))
Add Comment
Please, Sign In to add comment