Find least common multiple of 2 positive integers. :param x: int - first integer :param y: int - second integer :return: int - least common multiple >>> lcm(8, 4) 8 >>> lcm(5, 3) 15 >>> lcm(15, 9) 45 >>> lcm(124, 23) 2852 >>> lcm(
(x, y)
| 1 | def lcm(x, y): |
| 2 | """ |
| 3 | Find least common multiple of 2 positive integers. |
| 4 | :param x: int - first integer |
| 5 | :param y: int - second integer |
| 6 | :return: int - least common multiple |
| 7 | |
| 8 | >>> lcm(8, 4) |
| 9 | 8 |
| 10 | >>> lcm(5, 3) |
| 11 | 15 |
| 12 | >>> lcm(15, 9) |
| 13 | 45 |
| 14 | >>> lcm(124, 23) |
| 15 | 2852 |
| 16 | >>> lcm(3, 6) |
| 17 | 6 |
| 18 | >>> lcm(13, 34) |
| 19 | 442 |
| 20 | >>> lcm(235, 745) |
| 21 | 35015 |
| 22 | >>> lcm(65, 86) |
| 23 | 5590 |
| 24 | >>> lcm(0, 1) |
| 25 | -1 |
| 26 | >>> lcm(-12, 35) |
| 27 | -1 |
| 28 | """ |
| 29 | if x <= 0 or y <= 0: |
| 30 | return -1 |
| 31 | |
| 32 | if x > y: |
| 33 | greater_number = x |
| 34 | else: |
| 35 | greater_number = y |
| 36 | |
| 37 | while True: |
| 38 | if (greater_number % x == 0) and (greater_number % y == 0): |
| 39 | lcm = greater_number |
| 40 | break |
| 41 | greater_number += 1 |
| 42 | return lcm |
| 43 | |
| 44 | |
| 45 | num_1 = int(input("Enter first number: ")) |