Prime factorization - list

前端 未结 17 873
说谎
说谎 2020-11-27 05:06

I am trying to implement a function primeFac() that takes as input a positive integer n and returns a list containing all the numbers in the prime

17条回答
  •  星月不相逢
    2020-11-27 05:32

    Simple way to get the desired solution

    def Factor(n):
        d = 2
        factors = []
        while n >= d*d:
            if n % d == 0:
                n//=d
                # print(d,end = " ")
                factors.append(d)
            else:
                d = d+1
        if n>1:
            # print(int(n))
            factors.append(n)
        return factors
    

提交回复
热议问题