added alternative implementation making use of prime factors