Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # LCM or least common multiplier of two number is the smallest number that is divisible by both of these numbers.
- import sys
- def multiplier(x):
- i = 1
- while True:
- yield x * i
- i += 1
- def lcm(x, y):
- if x < y:
- x, y = y, x
- for i in multiplier(x):
- if i % y == 0:
- return i
- if __name__ == '__main__':
- x = int(sys.argv[1])
- y = int(sys.argv[2])
- if any([True for i in [x, y] if i < 0 or i == 0]):
- raise ValueError('both of the two numbers must be positive.')
- print(lcm(x, y))
Add Comment
Please, Sign In to add comment