题解 | #质数因子#

质数因子

https://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607?tpId=37&tqId=21229&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=

import math

while True:
    try:
        n = int(input())
        for i in range(2, int(math.sqrt(n)) + 1):
            while n % i == 0:
                if n % i == 0:
                    print(i, end=' ')
                    n /= i
        if n > 1:
            print(int(n))
    except:
        break

Python刷华为机考题 文章被收录于专栏

无聊刷刷!

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务