Is there a know algorithm to factor an integer into as few factors as possible (not necessarily prime) where every factor is less than some given constant N?
I don’t care about numbers with a prime factor greater than N. Also, I’m not dealing with numbers greater than a few million and the factoring is part of the processing initialization, so I’m not especially worried about computational complexity.
EDIT: Just to be clear. I already have code find the prime factors. I’m looking for a way to combine those factors into as few composite factors as possible while keeping each factor less than N.
You can solve your problem by dividing it into two parts:
Factorize your number into primes using any of the standard techniques. For a number of only a few million, trial division would be perfectly fine.
Take the logarithm of each factor, and pack them into bins of size log N.
Now, bin packing is NP-hard but in practice it is possible to find good approximate solutions using simple techniques: the first-fit algorithm packs no more than 11/9 times the optimal number of bins (plus one bin).
Here’s an implementation in Python: