Solved Problem 5 with prime factorization