.

Saturday, September 12, 2015

List of all unique pairs of prime factors of a number

import itertools

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

alist=primefactors(x)
for L in range(1, len(alist)+1):
         for subset in set(itertools.combinations(alist,L)):
            
            print(subset)


Console:

36
(2,)
(3,)
(2, 3)
(3, 3)
(2, 2)
(2, 2, 3)
(2, 3, 3)
(2, 2, 3, 3)

No comments :

Post a Comment

There was an error in this gadget