分解质因数

pyschools Topic 5: Question 12题目:分解质因素

Given a positive integer, write a function that computes the prime factors that can be multplied together to get back the same integer.

def primeFactorization(num): 
    factor=[]
    while num>1:
        for i in range(2,num+1):
            if num%i==0:
                factor.append(i)
                num = num//i
                break
    return factor

image

posted @ 2020-08-05 08:56  九命猫幺  阅读(209)  评论(0编辑  收藏  举报