problem 23 using factor sum algorithm from 21