Problem 47 and additions to Primes and Factors library