Advertisement
vasyukov

ZFTSH Programming Elements Task 4

Mar 29th, 2023
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. def gcd(a, b):
  2.     while a != 0 and b != 0:
  3.         if a > b:
  4.             a = a % b
  5.         else:
  6.             b = b % a
  7.     return a + b
  8.  
  9. def lcm(a, b):
  10.     return a * b // gcd(a, b)
  11.  
  12. gcd_n = 0
  13. lcm_n = 1
  14. n = int(input())
  15. while n != 0:
  16.     gcd_n = gcd(gcd_n, n)
  17.     lcm_n = lcm(lcm_n, n)
  18.     n = int(input())
  19.  
  20. print('НОД:', gcd_n)
  21. print('НОК:', lcm_n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement