fix(curriculum): clean-up Project Euler 341-360 (#42998)
* fix: clean-up Project Euler 341-360 * fix: improve wording Co-authored-by: Sem Bauke <46919888+Sembauke@users.noreply.github.com> * fix: corrections from review Co-authored-by: Tom <20648924+moT01@users.noreply.github.com> Co-authored-by: Sem Bauke <46919888+Sembauke@users.noreply.github.com> Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
This commit is contained in:
@ -8,20 +8,25 @@ dashedName: problem-341-golombs-self-describing-sequence
|
||||
|
||||
# --description--
|
||||
|
||||
The Golomb's self-describing sequence {G(n)} is the only nondecreasing sequence of natural numbers such that n appears exactly G(n) times in the sequence. The values of G(n) for the first few n are
|
||||
The Golomb's self-describing sequence ($G(n)$) is the only nondecreasing sequence of natural numbers such that $n$ appears exactly $G(n)$ times in the sequence. The values of $G(n)$ for the first few $n$ are
|
||||
|
||||
n123456789101112131415…G(n)122334445556666…
|
||||
$$\begin{array}{c}
|
||||
n & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & \ldots \\\\
|
||||
G(n) & 1 & 2 & 2 & 3 & 3 & 4 & 4 & 4 & 5 & 5 & 5 & 6 & 6 & 6 & 6 & \ldots
|
||||
\end{array}$$
|
||||
|
||||
You are given that G(103) = 86, G(106) = 6137. You are also given that ΣG(n3) = 153506976 for 1 ≤ n < 103.
|
||||
You are given that $G({10}^3) = 86$, $G({10}^6) = 6137$.
|
||||
|
||||
Find ΣG(n3) for 1 ≤ n < 106.
|
||||
You are also given that $\sum G(n^3) = 153\\,506\\,976$ for $1 ≤ n < {10}^3$.
|
||||
|
||||
Find $\sum G(n^3)$ for $1 ≤ n < {10}^6$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler341()` should return 56098610614277016.
|
||||
`golombsSequence()` should return `56098610614277016`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler341(), 56098610614277016);
|
||||
assert.strictEqual(golombsSequence(), 56098610614277016);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -29,12 +34,12 @@ assert.strictEqual(euler341(), 56098610614277016);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler341() {
|
||||
function golombsSequence() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler341();
|
||||
golombsSequence();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,20 +10,19 @@ dashedName: problem-342-the-totient-of-a-square-is-a-cube
|
||||
|
||||
Consider the number 50.
|
||||
|
||||
502 = 2500 = 22 × 54, so φ(2500) = 2 × 4 × 53 = 8 × 53 = 23 × 53. 1
|
||||
${50}^2 = 2500 = 2^2 × 5^4$, so $φ(2500) = 2 × 4 × 5^3 = 8 × 5^3 = 2^3 × 5^3$. $φ$ denotes Euler's totient function.
|
||||
|
||||
So 2500 is a square and φ(2500) is a cube.
|
||||
So 2500 is a square and $φ(2500)$ is a cube.
|
||||
|
||||
Find the sum of all numbers n, 1 < n < 1010 such that φ(n2) is a cube.
|
||||
Find the sum of all numbers $n$, $1 < n < {10}^{10}$ such that $φ(n^2)$ is a cube.
|
||||
|
||||
1 φ denotes Euler's totient function.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler342()` should return 5943040885644.
|
||||
`totientOfSquare()` should return `5943040885644`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler342(), 5943040885644);
|
||||
assert.strictEqual(totientOfSquare(), 5943040885644);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -31,12 +30,12 @@ assert.strictEqual(euler342(), 5943040885644);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler342() {
|
||||
function totientOfSquare() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler342();
|
||||
totientOfSquare();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,32 +8,31 @@ dashedName: problem-343-fractional-sequences
|
||||
|
||||
# --description--
|
||||
|
||||
For any positive integer k, a finite sequence ai of fractions xi/yi is defined by:
|
||||
For any positive integer $k$, a finite sequence $a_i$ of fractions $\frac{x_i}{y_i}$ is defined by:
|
||||
|
||||
a1 = 1/k and
|
||||
- $a_1 = \displaystyle\frac{1}{k}$ and
|
||||
- $a_i = \displaystyle\frac{(x_{i - 1} + 1)}{(y_{i - 1} - 1)}$ reduced to lowest terms for $i > 1$.
|
||||
|
||||
ai = (xi-1+1)/(yi-1-1) reduced to lowest terms for i>1.
|
||||
When $a_i$ reaches some integer $n$, the sequence stops. (That is, when $y_i = 1$.)
|
||||
|
||||
When ai reaches some integer n, the sequence stops. (That is, when yi=1.)
|
||||
Define $f(k) = n$.
|
||||
|
||||
Define f(k) = n.
|
||||
For example, for $k = 20$:
|
||||
|
||||
For example, for k = 20:
|
||||
$$\frac{1}{20} → \frac{2}{19} → \frac{3}{18} = \frac{1}{6} → \frac{2}{5} → \frac{3}{4} → \frac{4}{3} → \frac{5}{2} → \frac{6}{1} = 6$$
|
||||
|
||||
1/20 → 2/19 → 3/18 = 1/6 → 2/5 → 3/4 → 4/3 → 5/2 → 6/1 = 6
|
||||
So $f(20) = 6$.
|
||||
|
||||
So f(20) = 6.
|
||||
Also $f(1) = 1$, $f(2) = 2$, $f(3) = 1$ and $\sum f(k^3) = 118\\,937$ for $1 ≤ k ≤ 100$.
|
||||
|
||||
Also f(1) = 1, f(2) = 2, f(3) = 1 and Σf(k3) = 118937 for 1 ≤ k ≤ 100.
|
||||
|
||||
Find Σf(k3) for 1 ≤ k ≤ 2×106.
|
||||
Find $\sum f(k^3)$ for $1 ≤ k ≤ 2 × {10}^6$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler343()` should return 269533451410884200.
|
||||
`fractionalSequences()` should return `269533451410884200`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler343(), 269533451410884200);
|
||||
assert.strictEqual(fractionalSequences(), 269533451410884200);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -41,12 +40,12 @@ assert.strictEqual(euler343(), 269533451410884200);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler343() {
|
||||
function fractionalSequences() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler343();
|
||||
fractionalSequences();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -18,20 +18,22 @@ Alternatively, the player can choose to make the special move of pocketing the l
|
||||
|
||||
The winner is the player who pockets the silver dollar.
|
||||
|
||||
<img class="img-responsive center-block" alt="silver dollar game" src="https://cdn.freecodecamp.org/curriculum/project-euler/silver-dollar-game.gif" style="background-color: white; padding: 10px;">
|
||||
|
||||
A winning configuration is an arrangement of coins on the strip where the first player can force a win no matter what the second player does.
|
||||
|
||||
Let W(n,c) be the number of winning configurations for a strip of n squares, c worthless coins and one silver dollar.
|
||||
Let $W(n, c)$ be the number of winning configurations for a strip of $n$ squares, $c$ worthless coins and one silver dollar.
|
||||
|
||||
You are given that W(10,2) = 324 and W(100,10) = 1514704946113500.
|
||||
You are given that $W(10, 2) = 324$ and $W(100, 10) = 1\\,514\\,704\\,946\\,113\\,500$.
|
||||
|
||||
Find W(1 000 000, 100) modulo the semiprime 1000 036 000 099 (= 1 000 003 · 1 000 033).
|
||||
Find $W(1\\,000\\,000, 100)$ modulo the semiprime $1000\\,036\\,000\\,099 (= 1\\,000\\,003 \times 1\\,000\\,033)$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler344()` should return 65579304332.
|
||||
`silverDollarGame()` should return `65579304332`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler344(), 65579304332);
|
||||
assert.strictEqual(silverDollarGame(), 65579304332);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -39,12 +41,12 @@ assert.strictEqual(euler344(), 65579304332);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler344() {
|
||||
function silverDollarGame() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler344();
|
||||
silverDollarGame();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,20 +8,44 @@ dashedName: problem-345-matrix-sum
|
||||
|
||||
# --description--
|
||||
|
||||
We define the Matrix Sum of a matrix as the maximum sum of matrix elements with each element being the only one in his row and column. For example, the Matrix Sum of the matrix below equals 3315 ( = 863 + 383 + 343 + 959 + 767):
|
||||
We define the Matrix Sum of a matrix as the maximum sum of matrix elements with each element being the only one in his row and column.
|
||||
|
||||
7 53 183 439 863 497 383 563 79 973 287 63 343 169 583 627 343 773 959 943767 473 103 699 303
|
||||
For example, the Matrix Sum of the matrix below equals $3315 ( = 863 + 383 + 343 + 959 + 767)$:
|
||||
|
||||
$$\begin{array}{rrrrr}
|
||||
7 & 53 & 183 & 439 & \color{lime}{863} \\\\
|
||||
497 & \color{lime}{383} & 563 & 79 & 973 \\\\
|
||||
287 & 63 & \color{lime}{343} & 169 & 583 \\\\
|
||||
627 & 343 & 773 & \color{lime}{959} & 943 \\\\
|
||||
\color{lime}{767} & 473 & 103 & 699 & 303
|
||||
\end{array}$$
|
||||
|
||||
Find the Matrix Sum of:
|
||||
|
||||
7 53 183 439 863 497 383 563 79 973 287 63 343 169 583 627 343 773 959 943 767 473 103 699 303 957 703 583 639 913 447 283 463 29 23 487 463 993 119 883 327 493 423 159 743 217 623 3 399 853 407 103 983 89 463 290 516 212 462 350 960 376 682 962 300 780 486 502 912 800 250 346 172 812 350 870 456 192 162 593 473 915 45 989 873 823 965 425 329 803 973 965 905 919 133 673 665 235 509 613 673 815 165 992 326 322 148 972 962 286 255 941 541 265 323 925 281 601 95 973 445 721 11 525 473 65 511 164 138 672 18 428 154 448 848 414 456 310 312 798 104 566 520 302 248 694 976 430 392 198 184 829 373 181 631 101 969 613 840 740 778 458 284 760 390 821 461 843 513 17 901 711 993 293 157 274 94 192 156 574 34 124 4 878 450 476 712 914 838 669 875 299 823 329 699 815 559 813 459 522 788 168 586 966 232 308 833 251 631 107 813 883 451 509 615 77 281 613 459 205 380 274 302 35 805
|
||||
$$\\begin{array}{r}
|
||||
7 & 53 & 183 & 439 & 863 & 497 & 383 & 563 & 79 & 973 & 287 & 63 & 343 & 169 & 583 \\\\
|
||||
627 & 343 & 773 & 959 & 943 & 767 & 473 & 103 & 699 & 303 & 957 & 703 & 583 & 639 & 913 \\\\
|
||||
447 & 283 & 463 & 29 & 23 & 487 & 463 & 993 & 119 & 883 & 327 & 493 & 423 & 159 & 743 \\\\
|
||||
217 & 623 & 3 & 399 & 853 & 407 & 103 & 983 & 89 & 463 & 290 & 516 & 212 & 462 & 350 \\\\
|
||||
960 & 376 & 682 & 962 & 300 & 780 & 486 & 502 & 912 & 800 & 250 & 346 & 172 & 812 & 350 \\\\
|
||||
870 & 456 & 192 & 162 & 593 & 473 & 915 & 45 & 989 & 873 & 823 & 965 & 425 & 329 & 803 \\\\
|
||||
973 & 965 & 905 & 919 & 133 & 673 & 665 & 235 & 509 & 613 & 673 & 815 & 165 & 992 & 326 \\\\
|
||||
322 & 148 & 972 & 962 & 286 & 255 & 941 & 541 & 265 & 323 & 925 & 281 & 601 & 95 & 973 \\\\
|
||||
445 & 721 & 11 & 525 & 473 & 65 & 511 & 164 & 138 & 672 & 18 & 428 & 154 & 448 & 848 \\\\
|
||||
414 & 456 & 310 & 312 & 798 & 104 & 566 & 520 & 302 & 248 & 694 & 976 & 430 & 392 & 198 \\\\
|
||||
184 & 829 & 373 & 181 & 631 & 101 & 969 & 613 & 840 & 740 & 778 & 458 & 284 & 760 & 390 \\\\
|
||||
821 & 461 & 843 & 513 & 17 & 901 & 711 & 993 & 293 & 157 & 274 & 94 & 192 & 156 & 574 \\\\
|
||||
34 & 124 & 4 & 878 & 450 & 476 & 712 & 914 & 838 & 669 & 875 & 299 & 823 & 329 & 699 \\\\
|
||||
815 & 559 & 813 & 459 & 522 & 788 & 168 & 586 & 966 & 232 & 308 & 833 & 251 & 631 & 107 \\\\
|
||||
813 & 883 & 451 & 509 & 615 & 77 & 281 & 613 & 459 & 205 & 380 & 274 & 302 & 35 & 805
|
||||
\end{array}$$
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler345()` should return 13938.
|
||||
`matrixSum()` should return `13938`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler345(), 13938);
|
||||
assert.strictEqual(matrixSum(), 13938);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -29,12 +53,12 @@ assert.strictEqual(euler345(), 13938);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler345() {
|
||||
function matrixSum() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler345();
|
||||
matrixSum();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,18 +8,18 @@ dashedName: problem-346-strong-repunits
|
||||
|
||||
# --description--
|
||||
|
||||
The number 7 is special, because 7 is 111 written in base 2, and 11 written in base 6 (i.e. 710 = 116 = 1112). In other words, 7 is a repunit in at least two bases b > 1.
|
||||
The number 7 is special, because 7 is 111 written in base 2, and 11 written in base 6 (i.e. $7_{10} = {11}_6 = {111}_2$). In other words, 7 is a repunit in at least two bases $b > 1$.
|
||||
|
||||
We shall call a positive integer with this property a strong repunit. It can be verified that there are 8 strong repunits below 50: {1,7,13,15,21,31,40,43}. Furthermore, the sum of all strong repunits below 1000 equals 15864.
|
||||
We shall call a positive integer with this property a strong repunit. It can be verified that there are 8 strong repunits below 50: {1, 7, 13, 15, 21, 31, 40, 43}. Furthermore, the sum of all strong repunits below 1000 equals 15864.
|
||||
|
||||
Find the sum of all strong repunits below 1012.
|
||||
Find the sum of all strong repunits below ${10}^{12}$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler346()` should return 336108797689259260.
|
||||
`strongRepunits()` should return `336108797689259260`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler346(), 336108797689259260);
|
||||
assert.strictEqual(strongRepunits(), 336108797689259260);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -27,12 +27,12 @@ assert.strictEqual(euler346(), 336108797689259260);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler346() {
|
||||
function strongRepunits() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler346();
|
||||
strongRepunits();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,24 +8,24 @@ dashedName: problem-347-largest-integer-divisible-by-two-primes
|
||||
|
||||
# --description--
|
||||
|
||||
The largest integer ≤ 100 that is only divisible by both the primes 2 and 3 is 96, as 96=32\*3=25\*3.
|
||||
The largest integer $≤ 100$ that is only divisible by both the primes 2 and 3 is 96, as $96 = 32 \times 3 = 2^5 \times 3$.
|
||||
|
||||
For two distinct primes p and q let M(p,q,N) be the largest positive integer ≤N only divisible
|
||||
For two distinct primes $p$ and $q$ let $M(p, q, N)$ be the largest positive integer $≤ N$ only divisible by both $p$ and $q$ and $M(p, q, N)=0$ if such a positive integer does not exist.
|
||||
|
||||
by both p and q and M(p,q,N)=0 if such a positive integer does not exist.
|
||||
E.g. $M(2, 3, 100) = 96$.
|
||||
|
||||
E.g. M(2,3,100)=96. M(3,5,100)=75 and not 90 because 90 is divisible by 2 ,3 and 5. Also M(2,73,100)=0 because there does not exist a positive integer ≤ 100 that is divisible by both 2 and 73.
|
||||
$M(3, 5, 100) = 75$ and not 90 because 90 is divisible by 2, 3 and 5. Also $M(2, 73, 100) = 0$ because there does not exist a positive integer $≤ 100$ that is divisible by both 2 and 73.
|
||||
|
||||
Let S(N) be the sum of all distinct M(p,q,N). S(100)=2262.
|
||||
Let $S(N)$ be the sum of all distinct $M(p, q, N)$. $S(100)=2262$.
|
||||
|
||||
Find S(10 000 000).
|
||||
Find $S(10\\,000\\,000)$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler347()` should return 11109800204052.
|
||||
`integerDivisibleByTwoPrimes()` should return `11109800204052`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler347(), 11109800204052);
|
||||
assert.strictEqual(integerDivisibleByTwoPrimes(), 11109800204052);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -33,12 +33,12 @@ assert.strictEqual(euler347(), 11109800204052);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler347() {
|
||||
function integerDivisibleByTwoPrimes() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler347();
|
||||
integerDivisibleByTwoPrimes();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,16 +10,25 @@ dashedName: problem-348-sum-of-a-square-and-a-cube
|
||||
|
||||
Many numbers can be expressed as the sum of a square and a cube. Some of them in more than one way.
|
||||
|
||||
Consider the palindromic numbers that can be expressed as the sum of a square and a cube, both greater than 1, in exactly 4 different ways. For example, 5229225 is a palindromic number and it can be expressed in exactly 4 different ways: 22852 + 203 22232 + 663 18102 + 1253 11972 + 1563
|
||||
Consider the palindromic numbers that can be expressed as the sum of a square and a cube, both greater than 1, in exactly 4 different ways.
|
||||
|
||||
For example, 5229225 is a palindromic number and it can be expressed in exactly 4 different ways:
|
||||
|
||||
$$\begin{align}
|
||||
& {2285}^2 + {20}^3 \\\\
|
||||
& {2223}^2 + {66}^3 \\\\
|
||||
& {1810}^2 + {125}^3 \\\\
|
||||
& {1197}^2 + {156}^3
|
||||
\end{align}$$
|
||||
|
||||
Find the sum of the five smallest such palindromic numbers.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler348()` should return 1004195061.
|
||||
`sumOfSquareAndCube()` should return `1004195061`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler348(), 1004195061);
|
||||
assert.strictEqual(sumOfSquareAndCube(), 1004195061);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -27,12 +36,12 @@ assert.strictEqual(euler348(), 1004195061);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler348() {
|
||||
function sumOfSquareAndCube() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler348();
|
||||
sumOfSquareAndCube();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -12,18 +12,17 @@ An ant moves on a regular grid of squares that are coloured either black or whit
|
||||
|
||||
The ant is always oriented in one of the cardinal directions (left, right, up or down) and moves from square to adjacent square according to the following rules:
|
||||
|
||||
\- if it is on a black square, it flips the color of the square to white, rotates 90 degrees counterclockwise and moves forward one square.
|
||||
- if it is on a black square, it flips the color of the square to white, rotates 90° counterclockwise and moves forward one square.
|
||||
- if it is on a white square, it flips the color of the square to black, rotates 90° clockwise and moves forward one square.
|
||||
|
||||
\- if it is on a white square, it flips the color of the square to black, rotates 90 degrees clockwise and moves forward one square.
|
||||
|
||||
Starting with a grid that is entirely white, how many squares are black after 10<sup>18</sup> moves of the ant?
|
||||
Starting with a grid that is entirely white, how many squares are black after ${10}^{18}$ moves of the ant?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler349()` should return 115384615384614940.
|
||||
`langtonsAnt()` should return `115384615384614940`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler349(), 115384615384614940);
|
||||
assert.strictEqual(langtonsAnt(), 115384615384614940);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -31,12 +30,12 @@ assert.strictEqual(euler349(), 115384615384614940);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler349() {
|
||||
function langtonsAnt() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler349();
|
||||
langtonsAnt();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,24 +8,29 @@ dashedName: problem-350-constraining-the-least-greatest-and-the-greatest-least
|
||||
|
||||
# --description--
|
||||
|
||||
A list of size n is a sequence of n natural numbers. Examples are (2,4,6), (2,6,4), (10,6,15,6), and (11).
|
||||
A list of size $n$ is a sequence of $n$ natural numbers. Examples are (2, 4, 6), (2, 6, 4), (10, 6, 15, 6), and (11).
|
||||
|
||||
The greatest common divisor, or gcd, of a list is the largest natural number that divides all entries of the list. Examples: gcd(2,6,4) = 2, gcd(10,6,15,6) = 1 and gcd(11) = 11.
|
||||
The greatest common divisor, or $gcd$, of a list is the largest natural number that divides all entries of the list. Examples: $gcd(2, 6, 4) = 2$, $gcd(10, 6, 15, 6) = 1$ and $gcd(11) = 11$.
|
||||
|
||||
The least common multiple, or lcm, of a list is the smallest natural number divisible by each entry of the list. Examples: lcm(2,6,4) = 12, lcm(10,6,15,6) = 30 and lcm(11) = 11.
|
||||
The least common multiple, or $lcm$, of a list is the smallest natural number divisible by each entry of the list. Examples: $lcm(2, 6, 4) = 12$, $lcm(10, 6, 15, 6) = 30$ and $lcm(11) = 11$.
|
||||
|
||||
Let f(G, L, N) be the number of lists of size N with gcd ≥ G and lcm ≤ L. For example:
|
||||
Let $f(G, L, N)$ be the number of lists of size $N$ with $gcd ≥ G$ and $lcm ≤ L$. For example:
|
||||
|
||||
f(10, 100, 1) = 91. f(10, 100, 2) = 327. f(10, 100, 3) = 1135. f(10, 100, 1000) mod 1014 = 3286053.
|
||||
$$\begin{align}
|
||||
& f(10, 100, 1) = 91 \\\\
|
||||
& f(10, 100, 2) = 327 \\\\
|
||||
& f(10, 100, 3) = 1135 \\\\
|
||||
& f(10, 100, 1000)\bmod {101}^4 = 3\\,286\\,053
|
||||
\end{align}$$
|
||||
|
||||
Find f(106, 1012, 1018) mod 1014.
|
||||
Find $f({10}^6, {10}^{12}, {10}^{18})\bmod {101}^4$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler350()` should return 84664213.
|
||||
`leastGreatestAndGreatestLeast()` should return `84664213`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler350(), 84664213);
|
||||
assert.strictEqual(leastGreatestAndGreatestLeast(), 84664213);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -33,12 +38,12 @@ assert.strictEqual(euler350(), 84664213);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler350() {
|
||||
function leastGreatestAndGreatestLeast() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler350();
|
||||
leastGreatestAndGreatestLeast();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,22 +8,24 @@ dashedName: problem-351-hexagonal-orchards
|
||||
|
||||
# --description--
|
||||
|
||||
A hexagonal orchard of order n is a triangular lattice made up of points within a regular hexagon with side n. The following is an example of a hexagonal orchard of order 5:
|
||||
A hexagonal orchard of order $n$ is a triangular lattice made up of points within a regular hexagon with side $n$. The following is an example of a hexagonal orchard of order 5:
|
||||
|
||||
<img class="img-responsive center-block" alt="hexagonal orchard of order 5, with highlighted in green points, which are hidden from the center by a point closer to it" src="https://cdn.freecodecamp.org/curriculum/project-euler/hexagonal-orchards.png" style="background-color: white; padding: 10px;">
|
||||
|
||||
Highlighted in green are the points which are hidden from the center by a point closer to it. It can be seen that for a hexagonal orchard of order 5, 30 points are hidden from the center.
|
||||
|
||||
Let H(n) be the number of points hidden from the center in a hexagonal orchard of order n.
|
||||
Let $H(n)$ be the number of points hidden from the center in a hexagonal orchard of order $n$.
|
||||
|
||||
H(5) = 30. H(10) = 138. H(1 000) = 1177848.
|
||||
$H(5) = 30$. $H(10) = 138$. $H(1\\,000)$ = $1\\,177\\,848$.
|
||||
|
||||
Find H(100 000 000).
|
||||
Find $H(100\\,000\\,000)$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler351()` should return 11762187201804552.
|
||||
`hexagonalOrchards()` should return `11762187201804552`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler351(), 11762187201804552);
|
||||
assert.strictEqual(hexagonalOrchards(), 11762187201804552);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -31,12 +33,12 @@ assert.strictEqual(euler351(), 11762187201804552);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler351() {
|
||||
function hexagonalOrchards() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler351();
|
||||
hexagonalOrchards();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -12,28 +12,42 @@ Each one of the 25 sheep in a flock must be tested for a rare virus, known to af
|
||||
|
||||
An accurate and extremely sensitive PCR test exists for blood samples, producing a clear positive / negative result, but it is very time-consuming and expensive.
|
||||
|
||||
Because of the high cost, the vet-in-charge suggests that instead of performing 25 separate tests, the following procedure can be used instead: The sheep are split into 5 groups of 5 sheep in each group. For each group, the 5 samples are mixed together and a single test is performed. Then, If the result is negative, all the sheep in that group are deemed to be virus-free. If the result is positive, 5 additional tests will be performed (a separate test for each animal) to determine the affected individual(s).
|
||||
Because of the high cost, the vet-in-charge suggests that instead of performing 25 separate tests, the following procedure can be used instead:
|
||||
|
||||
Since the probability of infection for any specific animal is only 0.02, the first test (on the pooled samples) for each group will be: Negative (and no more tests needed) with probability 0.985 = 0.9039207968. Positive (5 additional tests needed) with probability 1 - 0.9039207968 = 0.0960792032.
|
||||
The sheep are split into 5 groups of 5 sheep in each group. For each group, the 5 samples are mixed together and a single test is performed. Then,
|
||||
|
||||
Thus, the expected number of tests for each group is 1 + 0.0960792032 × 5 = 1.480396016. Consequently, all 5 groups can be screened using an average of only 1.480396016 × 5 = 7.40198008 tests, which represents a huge saving of more than 70% !
|
||||
- If the result is negative, all the sheep in that group are deemed to be virus-free.
|
||||
- If the result is positive, 5 additional tests will be performed (a separate test for each animal) to determine the affected individual(s).
|
||||
|
||||
Although the scheme we have just described seems to be very efficient, it can still be improved considerably (always assuming that the test is sufficiently sensitive and that there are no adverse effects caused by mixing different samples). E.g.: We may start by running a test on a mixture of all the 25 samples. It can be verified that in about 60.35% of the cases this test will be negative, thus no more tests will be needed. Further testing will only be required for the remaining 39.65% of the cases. If we know that at least one animal in a group of 5 is infected and the first 4 individual tests come out negative, there is no need to run a test on the fifth animal (we know that it must be infected). We can try a different number of groups / different number of animals in each group, adjusting those numbers at each level so that the total expected number of tests will be minimised.
|
||||
Since the probability of infection for any specific animal is only 0.02, the first test (on the pooled samples) for each group will be:
|
||||
|
||||
- Negative (and no more tests needed) with probability ${0.98}^5 = 0.9039207968$.
|
||||
- Positive (5 additional tests needed) with probability $1 - 0.9039207968 = 0.0960792032$.
|
||||
|
||||
Thus, the expected number of tests for each group is $1 + 0.0960792032 × 5 = 1.480396016$.
|
||||
|
||||
Consequently, all 5 groups can be screened using an average of only $1.480396016 × 5 = \mathbf{7.40198008}$ tests, which represents a huge saving of more than 70%!
|
||||
|
||||
Although the scheme we have just described seems to be very efficient, it can still be improved considerably (always assuming that the test is sufficiently sensitive and no adverse effects are caused by mixing different samples). E.g.:
|
||||
|
||||
- We may start by running a test on a mixture of all the 25 samples. It can be verified that in about 60.35% of the cases this test will be negative, thus no more tests will be needed. Further testing will only be required for the remaining 39.65% of the cases.
|
||||
- If we know that at least one animal in a group of 5 is infected and the first 4 individual tests come out negative, there is no need to run a test on the fifth animal (we know that it must be infected).
|
||||
- We can try a different number of groups / different number of animals in each group, adjusting those numbers at each level so that the total expected number of tests will be minimised.
|
||||
|
||||
To simplify the very wide range of possibilities, there is one restriction we place when devising the most cost-efficient testing scheme: whenever we start with a mixed sample, all the sheep contributing to that sample must be fully screened (i.e. a verdict of infected / virus-free must be reached for all of them) before we start examining any other animals.
|
||||
|
||||
For the current example, it turns out that the most cost-efficient testing scheme (we'll call it the optimal strategy) requires an average of just 4.155452 tests!
|
||||
For the current example, it turns out that the most cost-efficient testing scheme (we'll call it the optimal strategy) requires an average of just <strong>4.155452</strong> tests!
|
||||
|
||||
Using the optimal strategy, let T(s,p) represent the average number of tests needed to screen a flock of s sheep for a virus having probability p to be present in any individual. Thus, rounded to six decimal places, T(25, 0.02) = 4.155452 and T(25, 0.10) = 12.702124.
|
||||
Using the optimal strategy, let $T(s, p)$ represent the average number of tests needed to screen a flock of $s$ sheep for a virus having probability $p$ to be present in any individual. Thus, rounded to six decimal places, $T(25, 0.02) = 4.155452$ and $T(25, 0.10) = 12.702124$.
|
||||
|
||||
Find ΣT(10000, p) for p=0.01, 0.02, 0.03, ... 0.50. Give your answer rounded to six decimal places.
|
||||
Find $\sum T(10\\,000, p)$ for $p = 0.01, 0.02, 0.03, \ldots 0.50$. Give your answer rounded to six decimal places.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler352()` should return 378563.260589.
|
||||
`bloodTests()` should return `378563.260589`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler352(), 378563.260589);
|
||||
assert.strictEqual(bloodTests(), 378563.260589);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -41,12 +55,12 @@ assert.strictEqual(euler352(), 378563.260589);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler352() {
|
||||
function bloodTests() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler352();
|
||||
bloodTests();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,28 +8,30 @@ dashedName: problem-353-risky-moon
|
||||
|
||||
# --description--
|
||||
|
||||
A moon could be described by the sphere C(r) with centre (0,0,0) and radius r.
|
||||
A moon could be described by the sphere $C(r)$ with centre (0, 0, 0) and radius $r$.
|
||||
|
||||
There are stations on the moon at the points on the surface of C(r) with integer coordinates. The station at (0,0,r) is called North Pole station, the station at (0,0,-r) is called South Pole station.
|
||||
There are stations on the moon at the points on the surface of $C(r)$ with integer coordinates. The station at (0, 0, $r$) is called North Pole station, the station at (0, 0, $-r$) is called South Pole station.
|
||||
|
||||
All stations are connected with each other via the shortest road on the great arc through the stations. A journey between two stations is risky. If d is the length of the road between two stations, (d/(π r))2 is a measure for the risk of the journey (let us call it the risk of the road). If the journey includes more than two stations, the risk of the journey is the sum of risks of the used roads.
|
||||
All stations are connected with each other via the shortest road on the great arc through the stations. A journey between two stations is risky. If $d$ is the length of the road between two stations, $\{\left(\frac{d}{πr}\right)}^2$ is a measure for the risk of the journey (let us call it the risk of the road). If the journey includes more than two stations, the risk of the journey is the sum of risks of the used roads.
|
||||
|
||||
A direct journey from the North Pole station to the South Pole station has the length πr and risk 1. The journey from the North Pole station to the South Pole station via (0,r,0) has the same length, but a smaller risk: (½πr/(πr))2+(½πr/(πr))2=0.5.
|
||||
A direct journey from the North Pole station to the South Pole station has the length $πr$ and risk 1. The journey from the North Pole station to the South Pole station via (0, $r$, 0) has the same length, but a smaller risk:
|
||||
|
||||
The minimal risk of a journey from the North Pole station to the South Pole station on C(r) is M(r).
|
||||
$${\left(\frac{\frac{1}{2}πr}{πr}\right)}^2+{\left(\frac{\frac{1}{2}πr}{πr}\right)}^2 = 0.5$$
|
||||
|
||||
You are given that M(7)=0.1784943998 rounded to 10 digits behind the decimal point.
|
||||
The minimal risk of a journey from the North Pole station to the South Pole station on $C(r)$ is $M(r)$.
|
||||
|
||||
Find ∑M(2n-1) for 1≤n≤15.
|
||||
You are given that $M(7) = 0.178\\,494\\,399\\,8$ rounded to 10 digits behind the decimal point.
|
||||
|
||||
Find $\displaystyle\sum_{n = 1}^{15} M(2^n - 1)$.
|
||||
|
||||
Give your answer rounded to 10 digits behind the decimal point in the form a.bcdefghijk.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler353()` should return 1.2759860331.
|
||||
`riskyMoon()` should return `1.2759860331`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler353(), 1.2759860331);
|
||||
assert.strictEqual(riskyMoon(), 1.2759860331);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -37,12 +39,12 @@ assert.strictEqual(euler353(), 1.2759860331);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler353() {
|
||||
function riskyMoon() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler353();
|
||||
riskyMoon();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,16 +10,20 @@ dashedName: problem-354-distances-in-a-bees-honeycomb
|
||||
|
||||
Consider a honey bee's honeycomb where each cell is a perfect regular hexagon with side length 1.
|
||||
|
||||
One particular cell is occupied by the queen bee. For a positive real number L, let B(L) count the cells with distance L from the queen bee cell (all distances are measured from centre to centre); you may assume that the honeycomb is large enough to accommodate for any distance we wish to consider. For example, B(√3) = 6, B(√21) = 12 and B(111 111 111) = 54.
|
||||
<img class="img-responsive center-block" alt="honeycomb with hexagon sides of length 1" src="https://cdn.freecodecamp.org/curriculum/project-euler/distances-in-a-bees-honeycomb.png" style="background-color: white; padding: 10px;">
|
||||
|
||||
Find the number of L ≤ 5·1011 such that B(L) = 450.
|
||||
One particular cell is occupied by the queen bee. For a positive real number $L$, let $B(L)$ count the cells with distance $L$ from the queen bee cell (all distances are measured from centre to centre); you may assume that the honeycomb is large enough to accommodate for any distance we wish to consider.
|
||||
|
||||
For example, $B(\sqrt{3}) = 6$, $B(\sqrt{21}) = 12$ and $B(111\\,111\\,111) = 54$.
|
||||
|
||||
Find the number of $L ≤ 5 \times {10}^{11}$ such that $B(L) = 450$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler354()` should return 58065134.
|
||||
`distancesInHoneycomb()` should return `58065134`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler354(), 58065134);
|
||||
assert.strictEqual(distancesInHoneycomb(), 58065134);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -27,12 +31,12 @@ assert.strictEqual(euler354(), 58065134);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler354() {
|
||||
function distancesInHoneycomb() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler354();
|
||||
distancesInHoneycomb();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,18 +8,18 @@ dashedName: problem-355-maximal-coprime-subset
|
||||
|
||||
# --description--
|
||||
|
||||
Define Co(n) to be the maximal possible sum of a set of mutually co-prime elements from {1, 2, ..., n}. For example Co(10) is 30 and hits that maximum on the subset {1, 5, 7, 8, 9}.
|
||||
Define $Co(n)$ to be the maximal possible sum of a set of mutually co-prime elements from $\\{1, 2, \ldots, n\\}$. For example $Co(10)$ is 30 and hits that maximum on the subset $\\{1, 5, 7, 8, 9\\}$.
|
||||
|
||||
You are given that Co(30) = 193 and Co(100) = 1356.
|
||||
You are given that $Co(30) = 193$ and $Co(100) = 1356$.
|
||||
|
||||
Find Co(200000).
|
||||
Find $Co(200\\,000)$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler355()` should return 1726545007.
|
||||
`maximalCoprimeSubset()` should return `1726545007`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler355(), 1726545007);
|
||||
assert.strictEqual(maximalCoprimeSubset(), 1726545007);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -27,12 +27,12 @@ assert.strictEqual(euler355(), 1726545007);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler355() {
|
||||
function maximalCoprimeSubset() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler355();
|
||||
maximalCoprimeSubset();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,20 +8,20 @@ dashedName: problem-356-largest-roots-of-cubic-polynomials
|
||||
|
||||
# --description--
|
||||
|
||||
Let an be the largest real root of a polynomial g(x) = x3 - 2n·x2 + n.
|
||||
Let an be the largest real root of a polynomial $g(x) = x^3 - 2^n \times x^2 + n$.
|
||||
|
||||
For example, a2 = 3.86619826...
|
||||
For example, $a_2 = 3.86619826\ldots$
|
||||
|
||||
Find the last eight digits of.
|
||||
Find the last eight digits of $\displaystyle\sum_{i = 1}^{30} \lfloor {a_i}^{987654321}\rfloor$.
|
||||
|
||||
Note: represents the floor function.
|
||||
**Note:** $\lfloor a\rfloor$ represents the floor function.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler356()` should return 28010159.
|
||||
`rootsOfCubicPolynomials()` should return `28010159`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler356(), 28010159);
|
||||
assert.strictEqual(rootsOfCubicPolynomials(), 28010159);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -29,12 +29,12 @@ assert.strictEqual(euler356(), 28010159);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler356() {
|
||||
function rootsOfCubicPolynomials() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler356();
|
||||
rootsOfCubicPolynomials();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,18 +8,18 @@ dashedName: problem-357-prime-generating-integers
|
||||
|
||||
# --description--
|
||||
|
||||
Consider the divisors of 30: 1,2,3,5,6,10,15,30.
|
||||
Consider the divisors of 30: 1, 2, 3, 5, 6, 10, 15, 30.
|
||||
|
||||
It can be seen that for every divisor d of 30, d+30/d is prime.
|
||||
It can be seen that for every divisor $d$ of 30, $d + \frac{30}{d}$ is prime.
|
||||
|
||||
Find the sum of all positive integers n not exceeding 100 000 000such that for every divisor d of n, d+n/d is prime.
|
||||
Find the sum of all positive integers $n$ not exceeding $100\\,000\\,000$ such that for every divisor $d$ of $n$, $d + \frac{n}{d}$ is prime.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler357()` should return 1739023853137.
|
||||
`primeGeneratingIntegers()` should return `1739023853137`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler357(), 1739023853137);
|
||||
assert.strictEqual(primeGeneratingIntegers(), 1739023853137);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -27,12 +27,12 @@ assert.strictEqual(euler357(), 1739023853137);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler357() {
|
||||
function primeGeneratingIntegers() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler357();
|
||||
primeGeneratingIntegers();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,24 +8,41 @@ dashedName: problem-358-cyclic-numbers
|
||||
|
||||
# --description--
|
||||
|
||||
A cyclic number with n digits has a very interesting property:
|
||||
A cyclic number with $n$ digits has a very interesting property:
|
||||
|
||||
When it is multiplied by 1, 2, 3, 4, ... n, all the products have exactly the same digits, in the same order, but rotated in a circular fashion!
|
||||
When it is multiplied by 1, 2, 3, 4, ... $n$, all the products have exactly the same digits, in the same order, but rotated in a circular fashion!
|
||||
|
||||
The smallest cyclic number is the 6-digit number 142857 : 142857 × 1 = 142857 142857 × 2 = 285714 142857 × 3 = 428571 142857 × 4 = 571428 142857 × 5 = 714285 142857 × 6 = 857142
|
||||
The smallest cyclic number is the 6-digit number 142857:
|
||||
|
||||
The next cyclic number is 0588235294117647 with 16 digits : 0588235294117647 × 1 = 0588235294117647 0588235294117647 × 2 = 1176470588235294 0588235294117647 × 3 = 1764705882352941 ... 0588235294117647 × 16 = 9411764705882352
|
||||
$$\begin{align}
|
||||
& 142857 × 1 = 142857 \\\\
|
||||
& 142857 × 2 = 285714 \\\\
|
||||
& 142857 × 3 = 428571 \\\\
|
||||
& 142857 × 4 = 571428 \\\\
|
||||
& 142857 × 5 = 714285 \\\\
|
||||
& 142857 × 6 = 857142
|
||||
\end{align}$$
|
||||
|
||||
The next cyclic number is 0588235294117647 with 16 digits:
|
||||
|
||||
$$\begin{align}
|
||||
& 0588235294117647 × 1 = 0588235294117647 \\\\
|
||||
& 0588235294117647 × 2 = 1176470588235294 \\\\
|
||||
& 0588235294117647 × 3 = 1764705882352941 \\\\
|
||||
& \ldots \\\\
|
||||
& 0588235294117647 × 16 = 9411764705882352
|
||||
\end{align}$$
|
||||
|
||||
Note that for cyclic numbers, leading zeros are important.
|
||||
|
||||
There is only one cyclic number for which, the eleven leftmost digits are 00000000137 and the five rightmost digits are 56789 (i.e., it has the form 00000000137...56789 with an unknown number of digits in the middle). Find the sum of all its digits.
|
||||
There is only one cyclic number for which, the eleven leftmost digits are 00000000137 and the five rightmost digits are 56789 (i.e., it has the form $00000000137\ldots56789$ with an unknown number of digits in the middle). Find the sum of all its digits.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler358()` should return 3284144505.
|
||||
`cyclicNumbers()` should return `3284144505`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler358(), 3284144505);
|
||||
assert.strictEqual(cyclicNumbers(), 3284144505);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -33,12 +50,12 @@ assert.strictEqual(euler358(), 3284144505);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler358() {
|
||||
function cyclicNumbers() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler358();
|
||||
cyclicNumbers();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,22 +10,40 @@ dashedName: problem-359-hilberts-new-hotel
|
||||
|
||||
An infinite number of people (numbered 1, 2, 3, etc.) are lined up to get a room at Hilbert's newest infinite hotel. The hotel contains an infinite number of floors (numbered 1, 2, 3, etc.), and each floor contains an infinite number of rooms (numbered 1, 2, 3, etc.).
|
||||
|
||||
Initially the hotel is empty. Hilbert declares a rule on how the nth person is assigned a room: person n gets the first vacant room in the lowest numbered floor satisfying either of the following: the floor is empty the floor is not empty, and if the latest person taking a room in that floor is person m, then m + n is a perfect square
|
||||
Initially the hotel is empty. Hilbert declares a rule on how the $n^{\text{th}}$ person is assigned a room: person $n$ gets the first vacant room in the lowest numbered floor satisfying either of the following:
|
||||
|
||||
Person 1 gets room 1 in floor 1 since floor 1 is empty. Person 2 does not get room 2 in floor 1 since 1 + 2 = 3 is not a perfect square. Person 2 instead gets room 1 in floor 2 since floor 2 is empty. Person 3 gets room 2 in floor 1 since 1 + 3 = 4 is a perfect square.
|
||||
- the floor is empty
|
||||
- the floor is not empty, and if the latest person taking a room in that floor is person $m$, then $m + n$ is a perfect square
|
||||
|
||||
Person 1 gets room 1 in floor 1 since floor 1 is empty.
|
||||
|
||||
Person 2 does not get room 2 in floor 1 since 1 + 2 = 3 is not a perfect square.
|
||||
|
||||
Person 2 instead gets room 1 in floor 2 since floor 2 is empty.
|
||||
|
||||
Person 3 gets room 2 in floor 1 since 1 + 3 = 4 is a perfect square.
|
||||
|
||||
Eventually, every person in the line gets a room in the hotel.
|
||||
|
||||
Define P(f, r) to be n if person n occupies room r in floor f, and 0 if no person occupies the room. Here are a few examples: P(1, 1) = 1 P(1, 2) = 3 P(2, 1) = 2 P(10, 20) = 440 P(25, 75) = 4863 P(99, 100) = 19454
|
||||
Define $P(f, r)$ to be $n$ if person $n$ occupies room $r$ in floor $f$, and 0 if no person occupies the room. Here are a few examples:
|
||||
|
||||
Find the sum of all P(f, r) for all positive f and r such that f × r = 71328803586048 and give the last 8 digits as your answer.
|
||||
$$\begin{align}
|
||||
& P(1, 1) = 1 \\\\
|
||||
& P(1, 2) = 3 \\\\
|
||||
& P(2, 1) = 2 \\\\
|
||||
& P(10, 20) = 440 \\\\
|
||||
& P(25, 75) = 4863 \\\\
|
||||
& P(99, 100) = 19454
|
||||
\end{align}$$
|
||||
|
||||
Find the sum of all $P(f, r)$ for all positive $f$ and $r$ such that $f × r = 71\\,328\\,803\\,586\\,048$ and give the last 8 digits as your answer.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler359()` should return 40632119.
|
||||
`hilbertsNewHotel()` should return `40632119`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler359(), 40632119);
|
||||
assert.strictEqual(hilbertsNewHotel(), 40632119);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -33,12 +51,12 @@ assert.strictEqual(euler359(), 40632119);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler359() {
|
||||
function hilbertsNewHotel() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler359();
|
||||
hilbertsNewHotel();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,20 +8,24 @@ dashedName: problem-360-scary-sphere
|
||||
|
||||
# --description--
|
||||
|
||||
Given two points (x1,y1,z1) and (x2,y2,z2) in three dimensional space, the Manhattan distance between those points is defined as |x1-x2|+|y1-y2|+|z1-z2|.
|
||||
Given two points ($x_1$, $y_1$, $z_1$) and ($x_2$, $y_2$, $z_2$) in three dimensional space, the Manhattan distance between those points is defined as $|x_1 - x_2| + |y_1 - y_2| + |z_1 - z_2|$.
|
||||
|
||||
Let C(r) be a sphere with radius r and center in the origin O(0,0,0). Let I(r) be the set of all points with integer coordinates on the surface of C(r). Let S(r) be the sum of the Manhattan distances of all elements of I(r) to the origin O.
|
||||
Let $C(r)$ be a sphere with radius $r$ and center in the origin $O(0, 0, 0)$.
|
||||
|
||||
E.g. S(45)=34518.
|
||||
Let $I(r)$ be the set of all points with integer coordinates on the surface of $C(r)$.
|
||||
|
||||
Find S(1010).
|
||||
Let $S(r)$ be the sum of the Manhattan distances of all elements of $I(r)$ to the origin $O$.
|
||||
|
||||
E.g. $S(45)=34518$.
|
||||
|
||||
Find $S({10}^{10})$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler360()` should return 878825614395267100.
|
||||
`scarySphere()` should return `878825614395267100`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler360(), 878825614395267100);
|
||||
assert.strictEqual(scarySphere(), 878825614395267100);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -29,12 +33,12 @@ assert.strictEqual(euler360(), 878825614395267100);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler360() {
|
||||
function scarySphere() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler360();
|
||||
scarySphere();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
Reference in New Issue
Block a user