2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
id: 5900f5271000cf542c51003a
|
|
|
|
title: 'Problem 443: GCD sequence'
|
2020-11-27 19:02:05 +01:00
|
|
|
challengeType: 5
|
2019-08-05 09:17:33 -07:00
|
|
|
forumTopicId: 302115
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: problem-443-gcd-sequence
|
2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --description--
|
2019-07-18 17:32:12 +02:00
|
|
|
|
2021-07-30 17:20:31 +02:00
|
|
|
Let $g(n)$ be a sequence defined as follows:
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2021-07-30 17:20:31 +02:00
|
|
|
$$\begin{align}
|
|
|
|
& g(4) = 13, \\\\
|
|
|
|
& g(n) = g(n-1) + gcd(n, g(n - 1)) \text{ for } n > 4.
|
|
|
|
\end{align}$$
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2021-07-30 17:20:31 +02:00
|
|
|
The first few values are:
|
2020-11-27 19:02:05 +01:00
|
|
|
|
2021-07-30 17:20:31 +02:00
|
|
|
$$\begin{array}{l}
|
|
|
|
n & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 & 20 & \ldots \\\\
|
|
|
|
g(n) & 13 & 14 & 16 & 17 & 18 & 27 & 28 & 29 & 30 & 31 & 32 & 33 & 34 & 51 & 54 & 55 & 60 & \ldots
|
|
|
|
\end{array}$$
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2021-07-30 17:20:31 +02:00
|
|
|
You are given that $g(1\\,000) = 2\\,524$ and $g(1\\,000\\,000) = 2\\,624\\,152$.
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2021-07-30 17:20:31 +02:00
|
|
|
Find $g({10}^{15})$.
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --hints--
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2021-07-30 17:20:31 +02:00
|
|
|
`gcdSequence()` should return `2744233049300770`.
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
2021-07-30 17:20:31 +02:00
|
|
|
assert.strictEqual(gcdSequence(), 2744233049300770);
|
2018-09-30 23:01:58 +01:00
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --seed--
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
## --seed-contents--
|
2018-09-30 23:01:58 +01:00
|
|
|
|
|
|
|
```js
|
2021-07-30 17:20:31 +02:00
|
|
|
function gcdSequence() {
|
2020-09-15 09:57:40 -07:00
|
|
|
|
2018-09-30 23:01:58 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-07-30 17:20:31 +02:00
|
|
|
gcdSequence();
|
2018-09-30 23:01:58 +01:00
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --solutions--
|
2018-09-30 23:01:58 +01:00
|
|
|
|
|
|
|
```js
|
|
|
|
// solution required
|
|
|
|
```
|