So I'm trying to figure out the best way to count the degeneracy of states for a 3-d particle in a box. The problem breaks into the following: we have three integers greater than or equal to unity whose values are allowed to vary independently, and the sum of whose squares equals a fourth integer. a2 + b2 + c2 = x It is required to find the allowed values of the fourth integer x, and the number of combinations of the first three integers (a, b, and c) able to produce each allowed fourth integer. At present the only method of solution I am aware of is just listing out the possibilities and counting by brute force, but I know there must be a better way. Any thoughts? Thanks in advance.