题解 | #求最小公倍数#
求最小公倍数
https://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3
import math # 1.提取正整数A和正整数B num = input().split() num1, num2 = int(num[0]), int(num[1]) # 2.如果num1可以被num2整除,返回num1 if num1 % num2 == 0: print(num1) # 3.如果num2可以被num1整除,返回num2 elif num2 % num1 == 0: print(num2) # 4.互相不能整除(先取最小公约数,有最小公约数,就返回两者乘积除以最小公约数。否则直接返回两者乘积) else: if num1 < num2: i = 2 temp = 0 while i < int(math.sqrt(num1)): if num1 % i == 0 and num2 % i == 0: temp = i break i = i + 1 if temp: print(num1 * num2 // temp) else: print(num1 * num2) if num1 > num2: i = 2 temp = 0 while i < int(math.sqrt(num2)): # print(i,num1,num2) if num1 % i == 0 and num2 % i == 0: temp = i break i = i + 1 if temp: print(num1 * num2 // temp) else: print(num1 * num2)