题解 | #质数因子#

质数因子

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

a = int(input().strip())
M = []#记录所有因子

def getPrime(a):
    if a == 2: 
        M.append(a)
        return
    
    for i in range(2,a//2):
        if a%i == 0: # 存在因数,则继续分解
            getPrime(i)
            getPrime(a//i)
            return
        if i*i > a: # 
            break
    #循环结束后,不存在因数,则本身为质数
    M.append(a)
    return

getPrime(a)
output = ""
for i in range(len(M)):
    output += str(M[i])
    output += ' '
print(output)
    
全部评论

相关推荐

不愿透露姓名的神秘牛友
06-26 14:50
人力小鱼姐:有后面墨迹那两句的时间问题早回答完了
点赞 评论 收藏
分享
牛客92804383...:在他心里你已经是他的员工了
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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