2018-10-10 18:03:03 -04:00
---
id: 5900f3e41000cf542c50fef7
2021-02-06 04:42:36 +00:00
title: 'Problem 120: Square remainders'
2018-10-10 18:03:03 -04:00
challengeType: 5
2021-02-06 04:42:36 +00:00
forumTopicId: 301747
2021-01-13 03:31:00 +01:00
dashedName: problem-120-square-remainders
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2018-10-10 18:03:03 -04:00
2021-07-15 13:04:11 +05:30
Let `r` be the remainder when ${(a − 1)}^n + {(a + 1)}^n$ is divided by $a^2$.
2021-02-06 04:42:36 +00:00
2021-07-15 13:04:11 +05:30
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$.
2021-02-06 04:42:36 +00:00
2021-07-15 13:04:11 +05:30
For $3 ≤ a ≤ 1000$, find $\sum{r}_{max}$.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --hints--
2018-10-10 18:03:03 -04:00
2021-07-15 13:04:11 +05:30
`squareRemainders()` should return `333082500` .
2018-10-10 18:03:03 -04:00
```js
2021-07-15 13:04:11 +05:30
assert.strictEqual(squareRemainders(), 333082500);
2018-10-10 18:03:03 -04:00
```
2021-01-13 03:31:00 +01:00
# --seed--
## --seed-contents--
```js
2021-07-15 13:04:11 +05:30
function squareRemainders() {
2021-01-13 03:31:00 +01:00
return true;
}
2021-07-15 13:04:11 +05:30
squareRemainders();
2021-01-13 03:31:00 +01:00
```
2020-12-16 00:37:30 -07:00
# --solutions--
2020-08-13 17:24:35 +02:00
2021-01-13 03:31:00 +01:00
```js
// solution required
```