refactored solution6 to use a formula to count the sum of squares rather than a loop