Optimize multiplesOfFactorsWithNumDigits in problem 4.