2018-09-30 22:01:58 +00:00
---
id: 5900f3e41000cf542c50fef7
title: 'Problem 120: Square remainders'
2020-11-27 18:02:05 +00:00
challengeType: 5
2019-08-05 16:17:33 +00:00
forumTopicId: 301747
2021-01-13 02:31:00 +00:00
dashedName: problem-120-square-remainders
2018-09-30 22:01:58 +00:00
---
2020-11-27 18:02:05 +00:00
# --description--
2021-06-30 12:25:46 +00:00
Let `r` be the remainder when ${(a − 1)}^n + {(a + 1)}^n$ is divided by $a^2$.
2018-09-30 22:01:58 +00:00
2021-06-30 12:25:46 +00:00
For example, if $a = 7$ and $n = 3$, then $r = 42: 6^3 + 8^3 = 728 ≡ 42 \\ \text{mod}\\ 49$. And as `n` varies, so too will `r` , but for $a = 7$ it turns out that $r_{max} = 42$.
2018-09-30 22:01:58 +00:00
2021-06-30 12:25:46 +00:00
For $3 ≤ a ≤ 1000$, find $\sum{r}_{max}$.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
# --hints--
2018-09-30 22:01:58 +00:00
2021-06-30 12:25:46 +00:00
`squareRemainders()` should return `333082500` .
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
2021-06-30 12:25:46 +00:00
assert.strictEqual(squareRemainders(), 333082500);
2018-09-30 22:01:58 +00:00
```
2020-11-27 18:02:05 +00:00
# --seed--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
## --seed-contents--
2018-09-30 22:01:58 +00:00
```js
2021-06-30 12:25:46 +00:00
function squareRemainders() {
2020-09-15 16:57:40 +00:00
2018-09-30 22:01:58 +00:00
return true;
}
2021-06-30 12:25:46 +00:00
squareRemainders();
2018-09-30 22:01:58 +00:00
```
2020-11-27 18:02:05 +00:00
# --solutions--
2018-09-30 22:01:58 +00:00
```js
// solution required
```