@SMcNeill
I too was confused about primes, we are always talking about prime factors and factoring numbers with primes.
Just concentrate on and count any number that divides evenly into the number we are checking.
2 would be smallest potential divisor and n/2 would be the largest potential divisor.
For any number n you have n/2 - 1 candidates for checking, a little math or other discoveries could (and did for me) speed up the processing tremendously! If you know a number is prime you know it won't have any divisors, but does that help much? Eh, maybe... ;-))
Actually, wouldn't n/8 would be the largest number to check as you're looking for 3 factors, and they have to be 2 x 2 x 2 at a minimum.
My idea is to pre-generate the prime numbers (which would be the factors), and then we'd only have to check primes from 2 to SQR(n) to check for factors for our number, with it growing ever smaller with each factor we pull out of it. My example does this nicely and fairly quickly. All I need to add, apparently, is a counter for number of factors found and if only 3 exist then I have a valid number.
I was just curious about the rest of the problem -- store the largest factor and sort the results. Are we sorting via that stored, largest factor? By the number itself?
I'm also curious about what the question calls a non-trivial divisor.
Let's use 16 as an example:
The factors are 2 x 2 x 2 x 2...
But could we say it has 3 nontrivial divisors? 2 x 2 x 4?
4 is still a divisor of 16, even if it isn't the most simplified or lowest common denominator...
If 2 x 2 x 4 counts, then the program becomes much quicker and simpler to run. Count factors, find 3, stop at the 3rd one and store it as it's going to be the highest factor. Then just sort your stored array.
Heck, if 2 x 2 x 4 counts for 16, then I'd just assemble a small preset array for quick elimination of most numbers.
For example, any number ending in zero can be instantly solved -- 2 * 5 * n /10 would give you the greatest denominator with 3 factors.
Check for numbers evenly divisible by 4, 6, 9, 10, 14... (2 * 2) (2 * 3) (3 * 3) (2 * 5) (2 * 7).. A quick list of a dozen fast pre-checks, or so, could probably eliminate over half of the problem with a single pass. The rest you can just factor out like normal afterwards. <-- It'd cut down on solving time considerably.