Problem 7 in scala for euler