2021-05-05 10:13:49 -07:00
|
|
|
|
---
|
|
|
|
|
id: 5900f3e41000cf542c50fef7
|
2021-11-23 11:06:14 -08:00
|
|
|
|
title: '問題 120:平方餘數'
|
2021-05-05 10:13:49 -07:00
|
|
|
|
challengeType: 5
|
|
|
|
|
forumTopicId: 301747
|
|
|
|
|
dashedName: problem-120-square-remainders
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# --description--
|
|
|
|
|
|
2021-11-23 11:06:14 -08:00
|
|
|
|
將 `r` 記爲當 ${(a − 1)}^n + {(a + 1)}^n$ 除以 $a^2$ 的餘數。
|
2021-05-05 10:13:49 -07:00
|
|
|
|
|
2021-11-23 11:06:14 -08:00
|
|
|
|
例如,如果 $a = 7$ 且 $n = 3$,則 $r = 42: 6^3 + 8^3 = 728 ≡ 42 \\ \text{mod}\\ 49$。 `r` 會隨着 `n` 的變化而變化,但對於 $a = 7$,會有 $r_{max} = 42$。
|
2021-05-05 10:13:49 -07:00
|
|
|
|
|
2021-11-23 11:06:14 -08:00
|
|
|
|
對於 $3 ≤ a ≤ 1000$,求 $\sum{r}_{max}$。
|
2021-05-05 10:13:49 -07:00
|
|
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
|
2021-11-23 11:06:14 -08:00
|
|
|
|
`squareRemainders()` 應該返回 `333082500`。
|
2021-05-05 10:13:49 -07:00
|
|
|
|
|
|
|
|
|
```js
|
2021-07-16 11:03:16 +05:30
|
|
|
|
assert.strictEqual(squareRemainders(), 333082500);
|
2021-05-05 10:13:49 -07:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
|
|
```js
|
2021-07-16 11:03:16 +05:30
|
|
|
|
function squareRemainders() {
|
2021-05-05 10:13:49 -07:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-16 11:03:16 +05:30
|
|
|
|
squareRemainders();
|
2021-05-05 10:13:49 -07:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# --solutions--
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
// solution required
|
|
|
|
|
```
|