prime factor implementation