Hello,
I'd like to propose a new option for GNU Coreutils' factor utility.
Currently:
------------------------------------------------------------------------
$ factor 72
72: 2 2 2 3 3
------------------------------------------------------------------------
I would like to add an option, tentatively -a, --all,
that prints all positive divisors of the number in ascending order:
------------------------------------------------------------------------
$ factor -a 72
72: 1 2 3 4 6 8 9 12 18 24 36 72
------------------------------------------------------------------------
The implementation would reuse the existing prime factorization.
For a factorization:
n = p_{1}^e_{1} * p_{2}^e_{2} * ... * p_{k}^e_{k}
where the p_{i} are distinct primes,
the divisors can be generated by considering all choices of exponents:
p_{1}^a_{1} * p_{2}^a_{2} * ... * p_{k}^a_{k}
where 0 <= a_{i} <= e_{i}.
I would keep the existing factoring algorithms unchanged
and add the divisor enumeration as an output mode after factorization.
The implementation would handle both
the existing native integer path and the GNU MP arbitrary-precision path.
I am new to contributing to Coreutils, so before I start writing
a substantial patch, I would appreciate guidance or comments
on whether this functionality would be considered a useful addition
and whether -a/--all would be an appropriate interface.
If the idea is considered worthwhile, I would also appreciate any advice
on the preferred implementation structure and tests.
I am happy to prepare the patch and
test it against the current development sources.
Would someone be willing to mentor/review the initial implementation
and/or the overall patch submission?
Thanks in advance for your time and energy,
Sophoklis