2021-06-15 00:49:18 -07:00
|
|
|
---
|
|
|
|
id: 5900f51d1000cf542c51002f
|
2022-03-04 19:46:29 +05:30
|
|
|
title: 'Problema 433: Passi nell''algoritmo di Euclide'
|
2021-06-15 00:49:18 -07:00
|
|
|
challengeType: 5
|
|
|
|
forumTopicId: 302104
|
|
|
|
dashedName: problem-433-steps-in-euclids-algorithm
|
|
|
|
---
|
|
|
|
|
|
|
|
# --description--
|
|
|
|
|
2022-03-04 19:46:29 +05:30
|
|
|
Sia $E(x_0, y_0)$ il numero di passi necessari a determinare il maggiore divisore comune di $x_0$ e $y_0$ con l'algoritmo di Euclide. Più formalmente:
|
2021-06-15 00:49:18 -07:00
|
|
|
|
2022-03-31 22:31:59 +05:30
|
|
|
$$$\start{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}$$
|
2021-06-15 00:49:18 -07:00
|
|
|
|
2022-03-04 19:46:29 +05:30
|
|
|
$E(x_0, y_0)$ è il più piccolo $n$ tale che $y_n = 0$.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
2022-03-04 19:46:29 +05:30
|
|
|
Abbiamo $E(1, 1) = 1$, $E(10, 6) = 3$ e $E(6, 10) = 4$.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
2022-03-04 19:46:29 +05:30
|
|
|
Definisci $S(N)$ come la somma di $E(x, y)$ per $1 ≤ x$, $y ≤ N$.
|
|
|
|
|
|
|
|
Abbiamo $S(1) = 1$, $S(10) = 221$ e $S(100) = 39\\,826$.
|
|
|
|
|
|
|
|
Trova $S(5 \times {10}^6)$.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
2022-03-04 19:46:29 +05:30
|
|
|
`stepsInEuclidsAlgorithm()` dovrebbe restituire `326624372659664`.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
```js
|
2022-03-04 19:46:29 +05:30
|
|
|
assert.strictEqual(stepsInEuclidsAlgorithm(), 326624372659664);
|
2021-06-15 00:49:18 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```js
|
2022-03-04 19:46:29 +05:30
|
|
|
function stepsInEuclidsAlgorithm() {
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-04 19:46:29 +05:30
|
|
|
stepsInEuclidsAlgorithm();
|
2021-06-15 00:49:18 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
# --solutions--
|
|
|
|
|
|
|
|
```js
|
|
|
|
// solution required
|
|
|
|
```
|