https://math.stackexchange.com/questions/1604414/sum-of-squares-using-generating-functions
proof of first part
64.3k questions
77.9k answers
243k comments
79.6k users