The rectangular spiral shown in the diagram is constructed as follows. Starting at $(0,0)$, line segments of lengths $1,1,2,2,3,3,4,4, \ldots$ are drawn in a clockwise manner, as shown. The integers from 1 to 1000 are placed, in increasing order, wherever the spiral passes through a point with integer coordinates (that is, 1 at $(0,0), 2$ at $(1,0), 3$ at $(1,-1)$, and so on). What is the sum of all of the positive integers from 1 to 1000 which are written at points on the line $y=-x$ ?

![](https://cdn.mathpix.com/cropped/2024_04_17_ff0a25f37b4b6ded9838g-3.jpg?height=567&width=561&top_left_y=215&top_left_x=1183)
We note that the first point $(0,0)$ attached to the integer 1 lies on the line $y=-x$.

In the diagram, line segments of lengths $1,1,2,2,3,3,4,4, \ldots$ are drawn starting at the origin.

We guess that the points on the spiral that lie on the line $y=-x$ are those obtained after an even number of these segments are drawn. (For example, the number 3 is at the point $(1,-1)$ after 2 segments, the number 7 is at the point $(-1,1)$ after 4 segments, the number 13 is at the point $(2,-2)$ after 6 segments, and so on.)

To see why this is true, we note that, after $2 k$ segments for some positive integer $k$, the $x$-coordinate of the endpoint is

$$
x=1-2+3-\ldots+(-1)^{k-1} k
$$

and the $y$-coordinate is

$$
y=-1+2-3+\ldots+(-1)^{k} k
$$

This is because the horizontal segments have lengths $1,2,3, \ldots, k$ and go right, left, right, left, etc., and the vertical segments have lengths $1,2,3, \ldots, k$ and go down, up, down, up, etc.

Note that $-1+2-3+\ldots+(-1)^{k} k=-\left(1-2+3-\ldots+(-1)^{k-1} k\right)$ and so these points lie on the line $y=-x$.

We note further that no more points on the spiral can lie on the line $y=-x$ since every second point at the end of a line segment lies on the line and the segment starting at a point on the line must move to a point off of the line.

At the point after $2 k$ segments, the integer written is

$1+(1+1+2+2+3+3+\ldots+k+k)=1+2(1+2+3+\ldots+k)=1+2\left(\frac{1}{2} k(k+1)\right)=1+k+k^{2}$

We want to determine the sum of the values of this expression starting with $k=1$ and continuing until the final one that is less than or equal to 1000.

We note that the expression is increasing as $k$ increases (as $k^{2}$ and $k$ are both increasing), that when $k=31,1+k+k^{2}=993$, and when $k=32,1+k+k^{2}=1057$.

Therefore, we want to calculate the sum of the values of $1+k+k^{2}$ from $k=0$ to $k=31$. (We start at $k=0$ to include the initial integer $1=1+0+0^{2}$.)

We obtain

$$
\begin{aligned}
\sum_{k=0}^{31}\left(1+k+k^{2}\right) & =\left(1+0+0^{2}\right)+\left(1+1+1^{2}\right)+\left(1+2+2^{2}\right)+\left(1+3+3^{2}\right)+\cdots+\left(1+31+31^{2}\right) \\
& =32 \cdot 1+(1+2+3+\cdots+31)+\left(1^{2}+2^{2}+3^{2}+\cdots+31^{2}\right) \\
& =32+\frac{1}{2}(31)(32)+\frac{1}{6}(31)(32)(63) \\
& \quad \text { (using the formulae given on the contest) } \\
& =32+496+10416 \\
& =10944
\end{aligned}
$$

(The notation on the left side in the first equation is called sigma notation and represents the sum on the right side of the first equation.)

Therefore, the sum of the positive integers from 1 to 1000 written at points on the line $y=-x$ is 10944 .

ANSWER: 10944