I propose to split the prime.properDivisors function in order to add a fast (no sort) Divisors function:
def Divisors(n):
"""
Return all divisors of n (including 1 and n).
"""
if n in (2, 3, 5, 7, 11, 13, 17, 19, 23):
return []
else:
l = [1]
for p, e in _factor(n):
for j in range(1, e + 1):
l += [k*pow(p, j) for k in l if k % p != 0]
def properDivisors(n):
"""
Return proper divisors of n (divisors of n excluding 1 and n).
It is only useful for a product of small primes.
One can use FactoredInteger.proper_divisors() as well.
"""
l=Divisors(n)
l.remove(1)
if n!=1:l.remove(n) # prevents properDivisors(1) from crashing
l.sort()
return l