Implemented prime factors selection logic