Problem 683: (2020 AIME II, 10)
Find the sum of all positive integers $n$ such that when $1^3+2^3+3^3+\cdots +n^3$ is divided by $n+5$, the remainder is $17$.
- The sum is $S=\left(\frac{n(n+1)}2\right)^2$, so $4S=n^2(n+1)^2\equiv25\cdot16=400\pmod{n+5}$. $S\equiv17$ implies $400\equiv68$, i.e.\ $n+5\mid332=4\cdot83$, with $n+5>17$.
- So $n+5\in\{83,166,332\}$, $n=78,161,327$. For odd $n+5$ the condition is equivalent; for even ones check directly.
- $n=78$ works; for $n=161$, $\frac{161\cdot162}2=13041\equiv93\pmod{166}$ and $93^2\equiv17$, works; for $n=327$, $53628\equiv176\pmod{332}$ and $176^2\equiv100$, fails.
- The sum is $78+161=239$. The answer is $\boxed{239}$.
Find the sum of all positive integers $n$ such that when $1^3+2^3+3^3+\cdots +n^3$ is divided by $n+7$, the remainder is $19$.