题解 | 质数因子

质数因子

https://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607

from math import sqrt

def factor(num: int) -> list:
    p = list()
    while num % 2 == 0:
        p.append(2)
        num //= 2

    for i in range(3, int(sqrt(num)) + 1, 2):
        while num % i == 0:
            p.append(i)
            num //= i

    if num > 1:
        p.append(num)

    return p

n = int(input())
p = factor(n)
for pi in p:
    print(pi, sep=' ', end=' ')

全部评论

相关推荐

求问!考研下岸,打算参加春招,我这个bg能进啥厂,或者需要搞点深度项目再投吗
Java抽象带篮子_...:直接海投,可以看看我的考研失利速成冲春招贴,里面详细写了简历怎么写,学哪些项目可以速成
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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