Calculate the sum of squares in constant time