Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Uses python3
- import sys
- from gcd.gcd import gcd_one_liner
- def lcm_naive(n, p):
- for l in range(1, n*p + 1):
- if l % n == 0 and l % p == 0:
- return l
- return n * p
- # we can obtain the least common multiple of (n,p) by dividing its product by their greatest
- # common divisor
- def lcm_faster(n, p):
- return int(n * p / gcd_one_liner(n, p))
- if __name__ == '__main__':
- user_input = sys.stdin.read()
- a, b = map(int, user_input.split())
- print(lcm_faster(a, b))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement