2018-09-30 22:01:58 +00:00
|
|
|
---
|
|
|
|
id: 5900f51d1000cf542c51002f
|
2018-10-20 18:02:47 +00:00
|
|
|
title: 'Problem 433: Steps in Euclid''s algorithm'
|
2020-11-27 18:02:05 +00:00
|
|
|
challengeType: 5
|
2019-08-05 16:17:33 +00:00
|
|
|
forumTopicId: 302104
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: problem-433-steps-in-euclids-algorithm
|
2018-09-30 22:01:58 +00:00
|
|
|
---
|
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
# --description--
|
|
|
|
|
2021-07-29 18:14:09 +00:00
|
|
|
Let $E(x_0, y_0)$ be the number of steps it takes to determine the greatest common divisor of $x_0$ and $y_0$ with Euclid's algorithm. More formally:
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2021-07-29 18:14:09 +00:00
|
|
|
$$\begin{align}
|
|
|
|
& x_1 = y_0, y_1 = x_0\bmod y_0 \\\\
|
|
|
|
& x_n = y_{n - 1}, y_n = x_{n - 1}\bmod y_{n - 1}
|
|
|
|
\end{align}$$
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2021-07-29 18:14:09 +00:00
|
|
|
$E(x_0, y_0)$ is the smallest $n$ such that $y_n = 0$.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2021-07-29 18:14:09 +00:00
|
|
|
We have $E(1, 1) = 1$, $E(10, 6) = 3$ and $E(6, 10) = 4$.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2021-07-29 18:14:09 +00:00
|
|
|
Define $S(N)$ as the sum of $E(x, y)$ for $1 ≤ x$, $y ≤ N$.
|
|
|
|
|
|
|
|
We have $S(1) = 1$, $S(10) = 221$ and $S(100) = 39\\,826$.
|
|
|
|
|
|
|
|
Find $S(5 \times {10}^6)$.
|
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-07-29 18:14:09 +00:00
|
|
|
`stepsInEuclidsAlgorithm()` should return `326624372659664`.
|
2018-09-30 22:01:58 +00:00
|
|
|
|
2020-11-27 18:02:05 +00:00
|
|
|
```js
|
2021-07-29 18:14:09 +00:00
|
|
|
assert.strictEqual(stepsInEuclidsAlgorithm(), 326624372659664);
|
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-07-29 18:14:09 +00:00
|
|
|
function stepsInEuclidsAlgorithm() {
|
2020-09-15 16:57:40 +00:00
|
|
|
|
2018-09-30 22:01:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-07-29 18:14:09 +00:00
|
|
|
stepsInEuclidsAlgorithm();
|
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
|
|
|
|
```
|