题解 | #求最小公倍数#
求最小公倍数
https://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3
import math a, b = map(int, input().split()) def cal_sushu(n): sushu = [] for i in range(2, int(math.sqrt(a)) + 1): if n % i == 0: n = n // i if i not in sushu: sushu.append(i) if n > 2: if n not in sushu: sushu.append(n) return sushu sushu_a = cal_sushu(a) sushu_b = cal_sushu(b) sushu_all = sushu_b.copy() for i in sushu_a: if i not in sushu_b: sushu_all.append(i) result = 1 for j in sushu_all: result = result * j print(result)
分别计算两个数的素数(分别都要去掉重复的素数),然后两个列表的素数去掉重复的素数,最后两个列表的素数相乘得到结果。