题解 | #质数因子#

质数因子

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-05 19:46
已编辑
武汉大学 后端
点赞 评论 收藏
分享
不亏是提前批,神仙打架,鼠鼠不配了
站队站对牛:现在92都报工艺岗了
投递韶音科技等公司7个岗位
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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