古老的知识是,每个非负整数都可以重写为四个平方整数的总和。例如,数字1可以表示为。或者,通常,对于任何非负整数,存在整数使得
Joseph-Louis Lagrange proved this in the 1700s and so it is often called Lagrange's Theorem.
This is sometimes discussed in relation to quaternions – a type of number discovered by William Hamilton in the 1800s, represented as
Rudolf Lipschitz studied quaternions with only integer components, called Lipschitz quaternions. Using quadrance, we can imagine that every Lipschitz quaternion can be thought of having a friend in the integers. For example quaternion can be thought of as associated with the integer . Also, if we go backwards, then every integer can be thought of as having a friend in the Lipschitz quaternions.
But there is an interesting detail of Lagrange's theorem – the summation is not unique. Each integer may have several different sets of four squares that can be summed to create it. For example, the number 1 can be expressed in 4 ways using non-negative integers (let us only consider non-negatives for this challenge):
The summands are always squares of 0, or 1, but they can be in different positions in the expression.
For this challenge, let us also "sort" our summands lowest to highest, to eliminate duplicates, so that we could consider, for this exercise, that 1 only has one way of being represented as the sum of four squares:
Another example is the number 42, which can be expressed in four ways (again, only considering non-negative a,b,c,d, and eliminating duplicate component arrangements)
What if we imagine each of these different ways of expressing an integer as being associated to a specific quaternion? Then we could say the number 42 is associated with these four quaternions:
If we imagine the standard computer graphics interpretation of a quaternion, where , and are vectors in three dimensional Euclidean space, and so the , and components of the quaternion are 3 dimensional Cartesian coordinates, then we can imagine that each integer, through this thought process, can be associated with a set of 3 dimensional coordinates in space. For example, the number 42 is associated with the following four coordinates:
This can be thought of as a point cloud, or a set of points in space. Now, one interesting thing about a set of finite points in space is that you can always draw a minimal bounding box around them – a box that is big enough to fit all the points, but no bigger. If you imagine the box as being an ordinary box aligned with the axes, it is called an axis-aligned bounding box. The bounding box also has a volume, calculable by determining its width, length, and height, and multiplying them together.
We can then imagine the volume of a bounding box for the points formed by our quaternions. For the integer 1, we have, using the criteria of this exercise, one quaternion whose quadrance is 1, . This is a very simple point cloud, it only has one point, so it's bounding box has volume 0. For the integer 42, however, we have four quaternions, and so four points, around which we can draw a bounding box. The minimum point of the box is and the maximum is resulting in a width, length, and height of 2, 2, and 2, giving a volume of 8.
Let's say that for an integer , the qvolume is the volume of the axis-aligned bounding box of all the 3D points formed by quaternions that have a quadrance equal to , where the components of the quaternion are non-negative and .
Create a program or function that, given a single non-negative integer , will output 's qvolume.
Examples:
input -> output
0 -> 0
1 -> 0
31 -> 4
32 -> 0
42 -> 8
137 -> 96
1729 -> 10032
This is code-golf, smallest number of bytes wins.