Refactor problem 1, using formula for sum of consecutive numbers