Prime factorization - list

前端 未结 17 841
说谎
说谎 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:10

    prime factors of a number:

    def primefactors(x):
        factorlist=[]
        loop=2
        while loop<=x:
            if x%loop==0:
                x//=loop
                factorlist.append(loop)
            else:
                loop+=1
        return factorlist
    
    x = int(input())
    alist=primefactors(x)
    print(alist)
    

    You'll get the list. If you want to get the pairs of prime factors of a number try this: http://pythonplanet.blogspot.in/2015/09/list-of-all-unique-pairs-of-prime.html

提交回复
热议问题