题解 | #求最小公倍数#

求最小公倍数

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)


分别计算两个数的素数(分别都要去掉重复的素数),然后两个列表的素数去掉重复的素数,最后两个列表的素数相乘得到结果。

全部评论

相关推荐

合适才能收到offe...:招聘上写这些态度傲慢的就别继续招呼了,你会发现hr和面试官挺神的,本来求职艰难就可能影响一些心态了,你去这种公司面试的话,整个心态会炸的。
点赞 评论 收藏
分享
03-06 17:17
门头沟学院 Java
程序员小白条:专升本提前注明,不然=白费,到最后面完,告诉你不能过,,还有这开源怎么前端大于后端....短链只写三个功能亮点的话,而且还是经典项目,反而可以不用,要么多写点东西,每个实习,项目都标准3点....
26届求职交流
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务