btilly wrote:You're solving the wrong problem. Permutations are just reorderings of the factors. What Berengal wants is closer to all subsets. But not exactly because of repeated factors.

Actually, I think he wants exactly all subsets of the set of factors. Pseudocode:

Code: Select all

`properDivisors(n):`

divisors = {}

for s in subsets(primeFactorization(n)):

divisors.append(product(s))

where:

primeFactorization returns the set of prime factors of n (including repeated factors)

subsets returns the power set of a set (i.e. the set of all subsets)

product returns the product of all members of a set.

note: since every set is a subset of itself (though not a proper subset), this pseudocode will return n as the largest divisor of n. This could be manually removed.

EDIT: oh, right, repeated factors. You're right, btilly. Don't use this algorithm, or insert a step that checks for duplicates.