# Revision history [back]

This is not a great answer but it's too long to fit in a comment. With N as in the question, it's faster than unitary_divisors1 but slower than unitary_divisors2. Partly taken from the top-ranked answer at https://stackoverflow.com/questions/1482308/how-to-get-all-subsets-of-a-set-powerset.

sage: from itertools import chain, combinations
sage: def unitary_divisors3(n):
....:     s = factor(n)
....:     C = chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
....:     return sorted(prod(p^k for p,k in f) for f in C)
....:

sage: %time L = len(unitary_divisors1(N))
CPU times: user 34.1 s, sys: 242 ms, total: 34.3 s
Wall time: 44.1 s
sage: %time L = len(unitary_divisors2(N))
CPU times: user 1.26 s, sys: 54.2 ms, total: 1.31 s
Wall time: 1.53 s
sage: %time L3 = len(unitary_divisors3(N))
CPU times: user 4.64 s, sys: 74.2 ms, total: 4.71 s
Wall time: 5.88 s


(My system is pretty heavily loaded right now; the timings for the first two were much faster earlier, but these are good for comparisons regardless.)

This is not a great answer but it's too long to fit in a comment. With N as in the question, it's faster than unitary_divisors1 but slower than unitary_divisors2. Partly taken from the top-ranked answer at https://stackoverflow.com/questions/1482308/how-to-get-all-subsets-of-a-set-powerset.https://stackoverflow.com/questions/1482308/how-to-get-all-subsets-of-a-set-powerset, also appearing as the powerset recipe at https://docs.python.org/3/library/itertools.html#recipes.

sage: from itertools import chain, combinations
sage: def unitary_divisors3(n):
....:     s = factor(n)
....:     C = chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
....:     return sorted(prod(p^k for p,k in f) for f in C)
....:

sage: %time L = len(unitary_divisors1(N))
CPU times: user 34.1 s, sys: 242 ms, total: 34.3 s
Wall time: 44.1 s
sage: %time L = len(unitary_divisors2(N))
CPU times: user 1.26 s, sys: 54.2 ms, total: 1.31 s
Wall time: 1.53 s
sage: %time L3 = len(unitary_divisors3(N))
CPU times: user 4.64 s, sys: 74.2 ms, total: 4.71 s
Wall time: 5.88 s


(My system is pretty heavily loaded right now; the timings for the first two were much faster earlier, but these are good for comparisons regardless.)