题解 | #质数因子#

质数因子

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

from math import sqrt

n = int(input())
N = n
results = []
i = 2
a, b = 1, 2
while True:
    if n % i == 0:
        results.append(i)
        n = int(n / i)
        a, b = n, i
    else:
        i += 1
    if i > sqrt(N):
        if n != 1:
            results.append(n)
        break
if len(results) > 0:
    print(" ".join(map(str, results)))
else:
    print(f'{N}')

全部评论

相关推荐

喜欢飞来飞去的雪碧在刷代码:可以试一试字节
点赞 评论 收藏
分享
深夜书店vv:腾讯是这样的,去年很多走廊都加桌子当工区
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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