posted 9 years ago
If you have a List of primes, you might do well to serialise it for future reference; why calculate the primes anew every time?
How about using a sieve of Eratosthenes, then populating your list of primes, then you can iterate through the List of numbers, and for an example like 4095 (3 × 3 × 5 × 7 × 13) you can calculate the factors very easily.
Use a pencil and paper and work out the prime factors of such a number: go through the method on paper then write down exactly how you did it. Then you have some pseudocode and you can easily convert that to real code. I think you are correctly checking for prime factors. How did you validate your isPrime() method? What you have written, with 8 unidentifiable local variables, looks very complicated.