fix: clean-up Project Euler 401-420 (#43028)

This commit is contained in:
gikf
2021-07-29 19:48:24 +02:00
committed by GitHub
parent c18554dd44
commit 7bd08ae2ee
20 changed files with 269 additions and 182 deletions

View File

@ -10,20 +10,20 @@ dashedName: problem-401-sum-of-squares-of-divisors
The divisors of 6 are 1, 2, 3 and 6.
The sum of the squares of these numbers is 1+4+9+36=50.
The sum of the squares of these numbers is $1 + 4 + 9 + 36 = 50$.
Let sigma2(n) represent the sum of the squares of the divisors of n. Thus sigma2(6)=50.
Let $\sigma_2(n)$ represent the sum of the squares of the divisors of $n$. Thus $\sigma_2(6) = 50$.
Let SIGMA2 represent the summatory function of sigma2, that is SIGMA2(n)=∑sigma2(i) for i=1 to n. The first 6 values of SIGMA2 are: 1,6,16,37,63 and 113.
Let $\Sigma_2$ represent the summatory function of $\sigma_2$, that is $\Sigma_2(n) = \sum \sigma_2(i)$ for $i=1$ to $n$. The first 6 values of $\Sigma_2$ are: 1, 6, 16, 37, 63 and 113.
Find SIGMA2(1015) modulo 109.
Find $\Sigma_2({10}^{15})$ modulo ${10}^9$.
# --hints--
`euler401()` should return 281632621.
`sumOfSquaresDivisors()` should return `281632621`.
```js
assert.strictEqual(euler401(), 281632621);
assert.strictEqual(sumOfSquaresDivisors(), 281632621);
```
# --seed--
@ -31,12 +31,12 @@ assert.strictEqual(euler401(), 281632621);
## --seed-contents--
```js
function euler401() {
function sumOfSquaresDivisors() {
return true;
}
euler401();
sumOfSquaresDivisors();
```
# --solutions--

View File

@ -8,24 +8,27 @@ dashedName: problem-402-integer-valued-polynomials
# --description--
It can be shown that the polynomial n4 + 4n3 + 2n2 + 5n is a multiple of 6 for every integer n. It can also be shown that 6 is the largest integer satisfying this property.
It can be shown that the polynomial $n^4 + 4n^3 + 2n^2 + 5n$ is a multiple of 6 for every integer $n$. It can also be shown that 6 is the largest integer satisfying this property.
Define M(a, b, c) as the maximum m such that n4 + an3 + bn2 + cn is a multiple of m for all integers n. For example, M(4, 2, 5) = 6.
Define $M(a, b, c)$ as the maximum $m$ such that $n^4 + an^3 + bn^2 + cn$ is a multiple of $m$ for all integers $n$. For example, $M(4, 2, 5) = 6$.
Also, define S(N) as the sum of M(a, b, c) for all 0 < a, b, c ≤ N.
Also, define $S(N)$ as the sum of $M(a, b, c)$ for all $0 < a, b, c ≤ N$.
We can verify that S(10) = 1972 and S(10000) = 2024258331114.
We can verify that $S(10) = 1\\,972$ and $S(10\\,000) = 2\\,024\\,258\\,331\\,114$.
Let Fk be the Fibonacci sequence: F0 = 0, F1 = 1 and Fk = Fk-1 + Fk-2 for k ≥ 2.
Let $F_k$ be the Fibonacci sequence:
Find the last 9 digits of Σ S(Fk) for 2 ≤ k ≤ 1234567890123.
- $F_0 = 0$, $F_1 = 1$ and
- $F_k = F_{k - 1} + F_{k - 2}$ for $k ≥ 2$.
Find the last 9 digits of $\sum S(F_k)$ for $2 ≤ k ≤ 1\\,234\\,567\\,890\\,123$.
# --hints--
`euler402()` should return 356019862.
`integerValuedPolynomials()` should return `356019862`.
```js
assert.strictEqual(euler402(), 356019862);
assert.strictEqual(integerValuedPolynomials(), 356019862);
```
# --seed--
@ -33,12 +36,12 @@ assert.strictEqual(euler402(), 356019862);
## --seed-contents--
```js
function euler402() {
function integerValuedPolynomials() {
return true;
}
euler402();
integerValuedPolynomials();
```
# --solutions--

View File

@ -8,20 +8,22 @@ dashedName: problem-403-lattice-points-enclosed-by-parabola-and-line
# --description--
For integers a and b, we define D(a, b) as the domain enclosed by the parabola y = x2 and the line y = a·x + b:D(a, b) = { (x, y) | x2 ≤ y ≤ a·x + b }.
For integers $a$ and $b$, we define $D(a, b)$ as the domain enclosed by the parabola $y = x^2$ and the line $y = ax + b: D(a, b) = \\{ (x, y) | x^2 ≤ y ≤ ax + b \\}$.
L(a, b) is defined as the number of lattice points contained in D(a, b). For example, L(1, 2) = 8 and L(2, -1) = 1.
$L(a, b)$ is defined as the number of lattice points contained in $D(a, b)$. For example, $L(1, 2) = 8$ and $L(2, -1) = 1$.
We also define S(N) as the sum of L(a, b) for all the pairs (a, b) such that the area of D(a, b) is a rational number and |a|,|b| ≤ N. We can verify that S(5) = 344 and S(100) = 26709528.
We also define $S(N)$ as the sum of $L(a, b)$ for all the pairs ($a$, $b$) such that the area of $D(a, b)$ is a rational number and $|a|,|b| ≤ N$.
Find S(1012). Give your answer mod 108.
We can verify that $S(5) = 344$ and $S(100) = 26\\,709\\,528$.
Find $S({10}^{12})$. Give your answer $\bmod {10}^8$.
# --hints--
`euler403()` should return 18224771.
`latticePoints()` should return `18224771`.
```js
assert.strictEqual(euler403(), 18224771);
assert.strictEqual(latticePoints(), 18224771);
```
# --seed--
@ -29,12 +31,12 @@ assert.strictEqual(euler403(), 18224771);
## --seed-contents--
```js
function euler403() {
function latticePoints() {
return true;
}
euler403();
latticePoints();
```
# --solutions--

View File

@ -8,22 +8,30 @@ dashedName: problem-404-crisscross-ellipses
# --description--
Ea is an ellipse with an equation of the form x2 + 4y2 = 4a2.
$E_a$ is an ellipse with an equation of the form $x^2 + 4y^2 = 4a^2$.
Ea' is the rotated image of Ea by θ degrees counterclockwise around the origin O(0, 0) for 0° < θ < 90°.
$E_a'$ is the rotated image of $E_a$ by $θ$ degrees counterclockwise around the origin $O(0, 0)$ for $< θ < 90°$.
b is the distance to the origin of the two intersection points closest to the origin and c is the distance of the two other intersection points. We call an ordered triplet (a, b, c) a canonical ellipsoidal triplet if a, b and c are positive integers. For example, (209, 247, 286) is a canonical ellipsoidal triplet.
<img class="img-responsive center-block" alt="ellipse E_a and ellipse rotated by θ degrees E_a'" src="https://cdn.freecodecamp.org/curriculum/project-euler/crisscross-ellipses.gif" style="background-color: white; padding: 10px;">
Let C(N) be the number of distinct canonical ellipsoidal triplets (a, b, c) for a ≤ N. It can be verified that C(103) = 7, C(104) = 106 and C(106) = 11845.
$b$ is the distance to the origin of the two intersection points closest to the origin and $c$ is the distance of the two other intersection points.
Find C(1017).
We call an ordered triplet ($a$, $b$, $c$) a canonical ellipsoidal triplet if $a$, $b$ and $c$ are positive integers.
For example, (209, 247, 286) is a canonical ellipsoidal triplet.
Let $C(N)$ be the number of distinct canonical ellipsoidal triplets ($a$, $b$, $c$) for $a ≤ N$.
It can be verified that $C({10}^3) = 7$, $C({10}^4) = 106$ and $C({10}^6) = 11\\,845$.
Find $C({10}^{17})$.
# --hints--
`euler404()` should return 1199215615081353.
`crisscrossEllipses()` should return `1199215615081353`.
```js
assert.strictEqual(euler404(), 1199215615081353);
assert.strictEqual(crisscrossEllipses(), 1199215615081353);
```
# --seed--
@ -31,12 +39,12 @@ assert.strictEqual(euler404(), 1199215615081353);
## --seed-contents--
```js
function euler404() {
function crisscrossEllipses() {
return true;
}
euler404();
crisscrossEllipses();
```
# --solutions--

View File

@ -10,22 +10,26 @@ dashedName: problem-405-a-rectangular-tiling
We wish to tile a rectangle whose length is twice its width.
Let T(0) be the tiling consisting of a single rectangle.
Let $T(0)$ be the tiling consisting of a single rectangle.
For n > 0, let T(n) be obtained from T(n-1) by replacing all tiles in the following manner:
For $n > 0$, let $T(n)$ be obtained from $T( n- 1)$ by replacing all tiles in the following manner:
The following animation demonstrates the tilings T(n) for n from 0 to 5:
<img class="img-responsive center-block" alt="obtaining T(n) from T(n - 1)" src="https://cdn.freecodecamp.org/curriculum/project-euler/a-rectangular-tiling-1.png" style="background-color: white; padding: 10px;">
Let f(n) be the number of points where four tiles meet in T(n). For example, f(1) = 0, f(4) = 82 and f(109) mod 177 = 126897180.
The following animation demonstrates the tilings $T(n)$ for $n$ from 0 to 5:
Find f(10k) for k = 1018, give your answer modulo 177.
<img class="img-responsive center-block" alt="animation with tilings T(n) for n from 0 to 5" src="https://cdn.freecodecamp.org/curriculum/project-euler/a-rectangular-tiling-2.gif" style="background-color: white; padding: 10px;">
Let $f(n)$ be the number of points where four tiles meet in $T(n)$. For example, $f(1) = 0$, $f(4) = 82$ and $f({10}^9)\bmod {17}^7 = 126\\,897\\,180$.
Find $f({10}^k)$ for $k = {10}^{18}$, give your answer modulo ${17}^7$.
# --hints--
`euler405()` should return 237696125.
`rectangularTiling()` should return `237696125`.
```js
assert.strictEqual(euler405(), 237696125);
assert.strictEqual(rectangularTiling(), 237696125);
```
# --seed--
@ -33,12 +37,12 @@ assert.strictEqual(euler405(), 237696125);
## --seed-contents--
```js
function euler405() {
function rectangularTiling() {
return true;
}
euler405();
rectangularTiling();
```
# --solutions--

View File

@ -8,32 +8,47 @@ dashedName: problem-406-guessing-game
# --description--
We are trying to find a hidden number selected from the set of integers {1, 2, ..., n} by asking questions.
We are trying to find a hidden number selected from the set of integers {1, 2, ..., $n$} by asking questions. Each number (question) we ask, we get one of three possible answers:
Each number (question) we ask, we get one of three possible answers: "Your guess is lower than the hidden number" (and you incur a cost of a), or
- "Your guess is lower than the hidden number" (and you incur a cost of a), or
- "Your guess is higher than the hidden number" (and you incur a cost of b), or
- "Yes, that's it!" (and the game ends).
"Your guess is higher than the hidden number" (and you incur a cost of b), or
Given the value of $n$, $a$, and $b$, an optimal strategy minimizes the total cost <u>for the worst possible case</u>.
"Yes, that's it!" (and the game ends).
For example, if $n = 5$, $a = 2$, and $b = 3$, then we may begin by asking "<strong>2</strong>" as our first question.
Given the value of n, a, and b, an optimal strategy minimizes the total cost for the worst possible case.
If we are told that 2 is higher than the hidden number (for a cost of $b = 3$), then we are sure that "<strong>1</strong>" is the hidden number (for a total cost of <strong><span style="color: blue;">3</span></strong>).
For example, if n = 5, a = 2, and b = 3, then we may begin by asking "2" as our first question.
If we are told that 2 is lower than the hidden number (for a cost of $a = 2$), then our next question will be "<strong>4</strong>".
If we are told that 2 is higher than the hidden number (for a cost of b=3), then we are sure that "1" is the hidden number (for a total cost of 3). If we are told that 2 is lower than the hidden number (for a cost of a=2), then our next question will be "4". If we are told that 4 is higher than the hidden number (for a cost of b=3), then we are sure that "3" is the hidden number (for a total cost of 2+3=5). If we are told that 4 is lower than the hidden number (for a cost of a=2), then we are sure that "5" is the hidden number (for a total cost of 2+2=4). Thus, the worst-case cost achieved by this strategy is 5. It can also be shown that this is the lowest worst-case cost that can be achieved. So, in fact, we have just described an optimal strategy for the given values of n, a, and b.
If we are told that 4 is higher than the hidden number (for a cost of $b = 3$), then we are sure that "<strong>3</strong>" is the hidden number (for a total cost of $2 + 3 = \color{blue}{\mathbf{5}}$).
Let C(n, a, b) be the worst-case cost achieved by an optimal strategy for the given values of n, a, and b.
If we are told that 4 is lower than the hidden number (for a cost of $a = 2$), then we are sure that "<strong>5</strong>" is the hidden number (for a total cost of $2 + 2 = \color{blue}{\mathbf{4}}$).
Here are a few examples: C(5, 2, 3) = 5 C(500, √2, √3) = 13.22073197... C(20000, 5, 7) = 82 C(2000000, √5, √7) = 49.63755955...
Thus, the worst-case cost achieved by this strategy is <strong><span style="color: red">5</span></strong>. It can also be shown that this is the lowest worst-case cost that can be achieved. So, in fact, we have just described an optimal strategy for the given values of $n$, $a$, and $b$.
Let Fk be the Fibonacci numbers: Fk = Fk-1 + Fk-2 with base cases F1 = F2 = 1.Find ∑1≤k≤30 C(1012, √k, √Fk), and give your answer rounded to 8 decimal places behind the decimal point.
Let $C(n, a, b)$ be the worst-case cost achieved by an optimal strategy for the given values of $n$, $a$, and $b$.
Here are a few examples:
$$\begin{align}
& C(5, 2, 3) = 5 \\\\
& C(500, \sqrt{2}, \sqrt{3}) = 13.220\\,731\\,97\ldots \\\\
& C(20\\,000, 5, 7) = 82 \\\\
& C(2\\,000\\,000, √5, √7) = 49.637\\,559\\,55\ldots \\\\
\end{align}$$
Let $F_k$ be the Fibonacci numbers: $F_k = F_{k - 1} + F_{k - 2}$ with base cases $F_1 = F_2 = 1$.
Find $\displaystyle\sum_{k = 1}^{30} C({10}^{12}, \sqrt{k}, \sqrt{F_k})$, and give your answer rounded to 8 decimal places behind the decimal point.
# --hints--
`euler406()` should return 36813.12757207.
`guessingGame()` should return `36813.12757207`.
```js
assert.strictEqual(euler406(), 36813.12757207);
assert.strictEqual(guessingGame(), 36813.12757207);
```
# --seed--
@ -41,12 +56,12 @@ assert.strictEqual(euler406(), 36813.12757207);
## --seed-contents--
```js
function euler406() {
function guessingGame() {
return true;
}
euler406();
guessingGame();
```
# --solutions--

View File

@ -8,18 +8,20 @@ dashedName: problem-407-idempotents
# --description--
If we calculate a2 mod 6 for 0 ≤ a ≤ 5 we get: 0,1,4,3,4,1.
If we calculate $a^2\bmod 6$ for $0 ≤ a ≤ 5$ we get: 0, 1, 4, 3, 4, 1.
The largest value of a such that a2 ≡ a mod 6 is 4. Let's call M(n) the largest value of a &lt; n such that a2 ≡ a (mod n). So M(6) = 4.
The largest value of a such that $a^2 ≡ a\bmod 6$ is $4$.
Find ∑M(n) for 1 ≤ n ≤ 107.
Let's call $M(n)$ the largest value of $a &lt; n$ such that $a^2 ≡ a (\text{mod } n)$. So $M(6) = 4$.
Find $\sum M(n)$ for $1 ≤ n ≤ {10}^7$.
# --hints--
`euler407()` should return 39782849136421.
`idempotents()` should return `39782849136421`.
```js
assert.strictEqual(euler407(), 39782849136421);
assert.strictEqual(idempotents(), 39782849136421);
```
# --seed--
@ -27,12 +29,12 @@ assert.strictEqual(euler407(), 39782849136421);
## --seed-contents--
```js
function euler407() {
function idempotents() {
return true;
}
euler407();
idempotents();
```
# --solutions--

View File

@ -8,22 +8,22 @@ dashedName: problem-408-admissible-paths-through-a-grid
# --description--
Let's call a lattice point (x, y) inadmissible if x, y and x + y are all positive perfect squares.
Let's call a lattice point ($x$, $y$) inadmissible if $x$, $y$ and $x + y$ are all positive perfect squares.
For example, (9, 16) is inadmissible, while (0, 4), (3, 1) and (9, 4) are not.
Consider a path from point (x1, y1) to point (x2, y2) using only unit steps north or east. Let's call such a path admissible if none of its intermediate points are inadmissible.
Consider a path from point ($x_1$, $y_1$) to point ($x_2$, $y_2$) using only unit steps north or east. Let's call such a path admissible if none of its intermediate points are inadmissible.
Let P(n) be the number of admissible paths from (0, 0) to (n, n). It can be verified that P(5) = 252, P(16) = 596994440 and P(1000) mod 1 000 000 007 = 341920854.
Let $P(n)$ be the number of admissible paths from (0, 0) to ($n$, $n$). It can be verified that $P(5) = 252$, $P(16) = 596\\,994\\,440$ and $P(1\\,000)\bmod 1\\,000\\,000\\,007 = 341\\,920\\,854$.
Find P(10 000 000) mod 1 000 000 007.
Find $P(10\\,000\\,000)\bmod 1\\,000\\,000\\,007$.
# --hints--
`euler408()` should return 299742733.
`admissiblePaths()` should return `299742733`.
```js
assert.strictEqual(euler408(), 299742733);
assert.strictEqual(admissiblePaths(), 299742733);
```
# --seed--
@ -31,12 +31,12 @@ assert.strictEqual(euler408(), 299742733);
## --seed-contents--
```js
function euler408() {
function admissiblePaths() {
return true;
}
euler408();
admissiblePaths();
```
# --solutions--

View File

@ -8,24 +8,24 @@ dashedName: problem-409-nim-extreme
# --description--
Let n be a positive integer. Consider nim positions where:There are n non-empty piles.
Let $n$ be a positive integer. Consider nim positions where:
Each pile has size less than 2n.
- There are $n$ non-empty piles.
- Each pile has size less than $2^n$.
- No two piles have the same size.
No two piles have the same size.
Let $W(n)$ be the number of winning nim positions satisfying the above conditions (a position is winning if the first player has a winning strategy).
Let W(n) be the number of winning nim positions satisfying the above
For example, $W(1) = 1$, $W(2) = 6$, $W(3) = 168$, $W(5) = 19\\,764\\,360$ and $W(100)\bmod 1\\,000\\,000\\,007 = 384\\,777\\,056$.
conditions (a position is winning if the first player has a winning strategy). For example, W(1) = 1, W(2) = 6, W(3) = 168, W(5) = 19764360 and W(100) mod 1 000 000 007 = 384777056.
Find W(10 000 000) mod 1 000 000 007.
Find $W(10\\,000\\,000)\bmod 1\\,000\\,000\\,007$.
# --hints--
`euler409()` should return 253223948.
`nimExtreme()` should return `253223948`.
```js
assert.strictEqual(euler409(), 253223948);
assert.strictEqual(nimExtreme(), 253223948);
```
# --seed--
@ -33,12 +33,12 @@ assert.strictEqual(euler409(), 253223948);
## --seed-contents--
```js
function euler409() {
function nimExtreme() {
return true;
}
euler409();
nimExtreme();
```
# --solutions--

View File

@ -8,20 +8,22 @@ dashedName: problem-410-circle-and-tangent-line
# --description--
Let C be the circle with radius r, x2 + y2 = r2. We choose two points P(a, b) and Q(-a, c) so that the line passing through P and Q is tangent to C.
Let $C$ be the circle with radius $r$, $x^2 + y^2 = r^2$. We choose two points $P(a, b)$ and $Q(-a, c)$ so that the line passing through $P$ and $Q$ is tangent to $C$.
For example, the quadruplet (r, a, b, c) = (2, 6, 2, -7) satisfies this property.
For example, the quadruplet $(r, a, b, c) = (2, 6, 2, -7)$ satisfies this property.
Let F(R, X) be the number of the integer quadruplets (r, a, b, c) with this property, and with 0 &lt; r ≤ R and 0 &lt; a ≤ X.
Let $F(R, X)$ be the number of the integer quadruplets $(r, a, b, c)$ with this property, and with $0 &lt; r ≤ R$ and $0 &lt; a ≤ X$.
We can verify that F(1, 5) = 10, F(2, 10) = 52 and F(10, 100) = 3384. Find F(108, 109) + F(109, 108).
We can verify that $F(1, 5) = 10$, $F(2, 10) = 52$ and $F(10, 100) = 3384$.
Find $F({10}^8, {10}^9) + F({10}^9, {10}^8)$.
# --hints--
`euler410()` should return 799999783589946600.
`circleAndTangentLine()` should return `799999783589946600`.
```js
assert.strictEqual(euler410(), 799999783589946600);
assert.strictEqual(circleAndTangentLine(), 799999783589946600);
```
# --seed--
@ -29,12 +31,12 @@ assert.strictEqual(euler410(), 799999783589946600);
## --seed-contents--
```js
function euler410() {
function circleAndTangentLine() {
return true;
}
euler410();
circleAndTangentLine();
```
# --solutions--

View File

@ -8,22 +8,26 @@ dashedName: problem-411-uphill-paths
# --description--
Let n be a positive integer. Suppose there are stations at the coordinates (x, y) = (2i mod n, 3i mod n) for 0 ≤ i ≤ 2n. We will consider stations with the same coordinates as the same station.
Let $n$ be a positive integer. Suppose there are stations at the coordinates $(x, y) = (2^i\bmod n, 3^i\bmod n)$ for $0 ≤ i ≤ 2n$. We will consider stations with the same coordinates as the same station.
We wish to form a path from (0, 0) to (n, n) such that the x and y coordinates never decrease. Let S(n) be the maximum number of stations such a path can pass through.
We wish to form a path from (0, 0) to ($n$, $n$) such that the $x$ and $y$ coordinates never decrease.
For example, if n = 22, there are 11 distinct stations, and a valid path can pass through at most 5 stations. Therefore, S(22) = 5. The case is illustrated below, with an example of an optimal path:
Let $S(n)$ be the maximum number of stations such a path can pass through.
It can also be verified that S(123) = 14 and S(10000) = 48.
For example, if $n = 22$, there are 11 distinct stations, and a valid path can pass through at most 5 stations. Therefore, $S(22) = 5$. The case is illustrated below, with an example of an optimal path:
Find ∑ S(k5) for 1 ≤ k ≤ 30.
<img class="img-responsive center-block" alt="valid path passing through 5 stations, for n = 22, with 11 distinct stations" src="https://cdn.freecodecamp.org/curriculum/project-euler/uphill-paths.png" style="background-color: white; padding: 10px;">
It can also be verified that $S(123) = 14$ and $S(10\\,000) = 48$.
Find $\sum S(k^5)$ for $1 ≤ k ≤ 30$.
# --hints--
`euler411()` should return 9936352.
`uphillPaths()` should return `9936352`.
```js
assert.strictEqual(euler411(), 9936352);
assert.strictEqual(uphillPaths(), 9936352);
```
# --seed--
@ -31,12 +35,12 @@ assert.strictEqual(euler411(), 9936352);
## --seed-contents--
```js
function euler411() {
function uphillPaths() {
return true;
}
euler411();
uphillPaths();
```
# --solutions--

View File

@ -8,24 +8,28 @@ dashedName: problem-412-gnomon-numbering
# --description--
For integers m, n (0 ≤ n &lt; m), let L(m, n) be an m×m grid with the top-right n×n grid removed.
For integers $m$, $n$ ($0 ≤ n &lt; m$), let $L(m, n)$ be an $m×m$ grid with the top-right $n×n$ grid removed.
For example, L(5, 3) looks like this:
For example, $L(5, 3)$ looks like this:
We want to number each cell of L(m, n) with consecutive integers 1, 2, 3, ... such that the number in every cell is smaller than the number below it and to the left of it.
<img class="img-responsive center-block" alt="5x5 grid, with removed 3x3 grid from the top-right" src="https://cdn.freecodecamp.org/curriculum/project-euler/gnomon-numbering-1.png" style="background-color: white; padding: 10px;">
For example, here are two valid numberings of L(5, 3):
We want to number each cell of $L(m, n)$ with consecutive integers 1, 2, 3, ... such that the number in every cell is smaller than the number below it and to the left of it.
Let LC(m, n) be the number of valid numberings of L(m, n). It can be verified that LC(3, 0) = 42, LC(5, 3) = 250250, LC(6, 3) = 406029023400 and LC(10, 5) mod 76543217 = 61251715.
For example, here are two valid numberings of $L(5, 3)$:
Find LC(10000, 5000) mod 76543217.
<img class="img-responsive center-block" alt="two valid numberings of L(5, 3)" src="https://cdn.freecodecamp.org/curriculum/project-euler/gnomon-numbering-2.png" style="background-color: white; padding: 10px;">
Let $LC(m, n)$ be the number of valid numberings of $L(m, n)$. It can be verified that $LC(3, 0) = 42$, $LC(5, 3) = 250\\,250$, $LC(6, 3) = 406\\,029\\,023\\,400$ and $LC(10, 5)\bmod 76\\,543\\,217 = 61\\,251\\,715$.
Find $LC(10\\,000, 5\\,000)\bmod 76\\,543\\,217$.
# --hints--
`euler412()` should return 38788800.
`gnomonNumbering()` should return `38788800`.
```js
assert.strictEqual(euler412(), 38788800);
assert.strictEqual(gnomonNumbering(), 38788800);
```
# --seed--
@ -33,12 +37,12 @@ assert.strictEqual(euler412(), 38788800);
## --seed-contents--
```js
function euler412() {
function gnomonNumbering() {
return true;
}
euler412();
gnomonNumbering();
```
# --solutions--

View File

@ -8,20 +8,22 @@ dashedName: problem-413-one-child-numbers
# --description--
We say that a d-digit positive number (no leading zeros) is a one-child number if exactly one of its sub-strings is divisible by d.
We say that a $d$-digit positive number (no leading zeros) is a one-child number if exactly one of its sub-strings is divisible by $d$.
For example, 5671 is a 4-digit one-child number. Among all its sub-strings 5, 6, 7, 1, 56, 67, 71, 567, 671 and 5671, only 56 is divisible by 4. Similarly, 104 is a 3-digit one-child number because only 0 is divisible by 3. 1132451 is a 7-digit one-child number because only 245 is divisible by 7.
For example, 5671 is a 4-digit one-child number. Among all its sub-strings 5, 6, 7, 1, 56, 67, 71, 567, 671 and 5671, only 56 is divisible by 4.
Let F(N) be the number of the one-child numbers less than N. We can verify that F(10) = 9, F(103) = 389 and F(107) = 277674.
Similarly, 104 is a 3-digit one-child number because only 0 is divisible by 3. 1132451 is a 7-digit one-child number because only 245 is divisible by 7.
Find F(1019).
Let $F(N)$ be the number of the one-child numbers less than $N$. We can verify that $F(10) = 9$, $F({10}^3) = 389$ and $F({10}^7) = 277\\,674$.
Find $F({10}^{19})$.
# --hints--
`euler413()` should return 3079418648040719.
`oneChildNumbers()` should return `3079418648040719`.
```js
assert.strictEqual(euler413(), 3079418648040719);
assert.strictEqual(oneChildNumbers(), 3079418648040719);
```
# --seed--
@ -29,12 +31,12 @@ assert.strictEqual(euler413(), 3079418648040719);
## --seed-contents--
```js
function euler413() {
function oneChildNumbers() {
return true;
}
euler413();
oneChildNumbers();
```
# --solutions--

View File

@ -8,7 +8,7 @@ dashedName: problem-414-kaprekar-constant
# --description--
6174 is a remarkable number; if we sort its digits in increasing order and subtract that number from the number you get when you sort the digits in decreasing order, we get 7641-1467=6174.
6174 is a remarkable number; if we sort its digits in increasing order and subtract that number from the number you get when you sort the digits in decreasing order, we get $7641 - 1467 = 6174$.
Even more remarkable is that if we start from any 4 digit number and repeat this process of sorting and subtracting, we'll eventually end up with 6174 or immediately with 0 if all digits are equal.
@ -16,28 +16,34 @@ This also works with numbers that have less than 4 digits if we pad the number w
E.g. let's start with the number 0837:
8730-0378=8352
8532-2358=6174
$$\begin{align}
& 8730 - 0378 = 8352 \\\\
& 8532 - 2358 = 6174
\end{align}$$
6174 is called the Kaprekar constant. The process of sorting and subtracting and repeating this until either 0 or the Kaprekar constant is reached is called the Kaprekar routine.
We can consider the Kaprekar routine for other bases and number of digits. Unfortunately, it is not guaranteed a Kaprekar constant exists in all cases; either the routine can end up in a cycle for some input numbers or the constant the routine arrives at can be different for different input numbers. However, it can be shown that for 5 digits and a base b = 6t+3≠9, a Kaprekar constant exists. E.g. base 15: (10,4,14,9,5)15 base 21: (14,6,20,13,7)21
We can consider the Kaprekar routine for other bases and number of digits. Unfortunately, it is not guaranteed a Kaprekar constant exists in all cases; either the routine can end up in a cycle for some input numbers or the constant the routine arrives at can be different for different input numbers. However, it can be shown that for 5 digits and a base $b = 6t + 3 ≠ 9$, a Kaprekar constant exists.
Define Cb to be the Kaprekar constant in base b for 5 digits. Define the function sb(i) to be 0 if i = Cb or if i written in base b consists of 5 identical digits the number of iterations it takes the Kaprekar routine in base b to arrive at Cb, otherwise
E.g. base 15: ${(10, 4, 14, 9, 5)}\_{15}$ base 21: $(14, 6, 20, 13, 7)_{21}$
Note that we can define sb(i) for all integers i &lt; b5. If i written in base b takes less than 5 digits, the number is padded with leading zero digits until we have 5 digits before applying the Kaprekar routine.
Define $C_b$ to be the Kaprekar constant in base $b$ for 5 digits. Define the function $sb(i)$ to be:
Define S(b) as the sum of sb(i) for 0 &lt; i &lt; b5. E.g. S(15) = 5274369 S(111) = 400668930299
- 0 if $i = C_b$ or if $i$ written in base $b$ consists of 5 identical digits
- the number of iterations it takes the Kaprekar routine in base $b$ to arrive at $C_b$, otherwise
Find the sum of S(6k+3) for 2 ≤ k ≤ 300. Give the last 18 digits as your answer.
Note that we can define $sb(i)$ for all integers $i &lt; b^5$. If $i$ written in base $b$ takes less than 5 digits, the number is padded with leading zero digits until we have 5 digits before applying the Kaprekar routine.
Define $S(b)$ as the sum of $sb(i)$ for $0 &lt; i &lt; b^5$. E.g. $S(15) = 5\\,274\\,369$ $S(111) = 400\\,668\\,930\\,299$
Find the sum of $S(6k + 3)$ for $2 ≤ k ≤ 300$. Give the last 18 digits as your answer.
# --hints--
`euler414()` should return 552506775824935500.
`kaprekarConstant()` should return `552506775824935500`.
```js
assert.strictEqual(euler414(), 552506775824935500);
assert.strictEqual(kaprekarConstant(), 552506775824935500);
```
# --seed--
@ -45,12 +51,12 @@ assert.strictEqual(euler414(), 552506775824935500);
## --seed-contents--
```js
function euler414() {
function kaprekarConstant() {
return true;
}
euler414();
kaprekarConstant();
```
# --solutions--

View File

@ -8,22 +8,22 @@ dashedName: problem-415-titanic-sets
# --description--
A set of lattice points S is called a titanic set if there exists a line passing through exactly two points in S.
A set of lattice points $S$ is called a titanic set if there exists a line passing through exactly two points in $S$.
An example of a titanic set is S = {(0, 0), (0, 1), (0, 2), (1, 1), (2, 0), (1, 0)}, where the line passing through (0, 1) and (2, 0) does not pass through any other point in S.
An example of a titanic set is $S = \\{(0, 0), (0, 1), (0, 2), (1, 1), (2, 0), (1, 0)\\}$, where the line passing through (0, 1) and (2, 0) does not pass through any other point in $S$.
On the other hand, the set {(0, 0), (1, 1), (2, 2), (4, 4)} is not a titanic set since the line passing through any two points in the set also passes through the other two.
For any positive integer N, let T(N) be the number of titanic sets S whose every point (x, y) satisfies 0 ≤ x, y ≤ N. It can be verified that T(1) = 11, T(2) = 494, T(4) = 33554178, T(111) mod 108 = 13500401 and T(105) mod 108 = 63259062.
For any positive integer $N$, let $T(N)$ be the number of titanic sets $S$ whose every point ($x$, $y$) satisfies $0 ≤ x$, $y ≤ N$. It can be verified that $T(1) = 11$, $T(2) = 494$, $T(4) = 33\\,554\\,178$, $T(111)\bmod {10}^8 = 13\\,500\\,401$ and $T({10}^5)\bmod {10}^8 = 63\\,259\\,062$.
Find T(1011) mod 108.
Find $T({10}^{11})\bmod {10}^8$.
# --hints--
`euler415()` should return 55859742.
`titanicSets()` should return `55859742`.
```js
assert.strictEqual(euler415(), 55859742);
assert.strictEqual(titanicSets(), 55859742);
```
# --seed--
@ -31,12 +31,12 @@ assert.strictEqual(euler415(), 55859742);
## --seed-contents--
```js
function euler415() {
function titanicSets() {
return true;
}
euler415();
titanicSets();
```
# --solutions--

View File

@ -8,18 +8,20 @@ dashedName: problem-416-a-frogs-trip
# --description--
A row of n squares contains a frog in the leftmost square. By successive jumps the frog goes to the rightmost square and then back to the leftmost square. On the outward trip he jumps one, two or three squares to the right, and on the homeward trip he jumps to the left in a similar manner. He cannot jump outside the squares. He repeats the round-trip travel m times.
A row of $n$ squares contains a frog in the leftmost square. By successive jumps the frog goes to the rightmost square and then back to the leftmost square. On the outward trip he jumps one, two or three squares to the right, and on the homeward trip he jumps to the left in a similar manner. He cannot jump outside the squares. He repeats the round-trip travel $m$ times.
Let F(m, n) be the number of the ways the frog can travel so that at most one square remains unvisited. For example, F(1, 3) = 4, F(1, 4) = 15, F(1, 5) = 46, F(2, 3) = 16 and F(2, 100) mod 109 = 429619151.
Let $F(m, n)$ be the number of the ways the frog can travel so that at most one square remains unvisited.
Find the last 9 digits of F(10, 1012).
For example, $F(1, 3) = 4$, $F(1, 4) = 15$, $F(1, 5) = 46$, $F(2, 3) = 16$ and $F(2, 100)\bmod {10}^9 = 429\\,619\\,151$.
Find the last 9 digits of $F(10, {10}^{12})$.
# --hints--
`euler416()` should return 898082747.
`frogsTrip()` should return `898082747`.
```js
assert.strictEqual(euler416(), 898082747);
assert.strictEqual(frogsTrip(), 898082747);
```
# --seed--
@ -27,12 +29,12 @@ assert.strictEqual(euler416(), 898082747);
## --seed-contents--
```js
function euler416() {
function frogsTrip() {
return true;
}
euler416();
frogsTrip();
```
# --solutions--

View File

@ -10,22 +10,32 @@ dashedName: problem-417-reciprocal-cycles-ii
A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given:
1/2= 0.5 1/3= 0.(3) 1/4= 0.25 1/5= 0.2 1/6= 0.1(6) 1/7= 0.(142857) 1/8= 0.125 1/9= 0.(1) 1/10= 0.1
$$\begin{align}
& \frac{1}{2} = 0.5 \\\\
& \frac{1}{3} = 0.(3) \\\\
& \frac{1}{4} = 0.25 \\\\
& \frac{1}{5} = 0.2 \\\\
& \frac{1}{6} = 0.1(6) \\\\
& \frac{1}{7} = 0.(142857) \\\\
& \frac{1}{8} = 0.125 \\\\
& \frac{1}{9} = 0.(1) \\\\
& \frac{1}{10} = 0.1 \\\\
\end{align}$$
Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle.
Where $0.1(6)$ means $0.166666\ldots$, and has a 1-digit recurring cycle. It can be seen that $\frac{1}{7}$ has a 6-digit recurring cycle.
Unit fractions whose denominator has no other prime factors than 2 and/or 5 are not considered to have a recurring cycle. We define the length of the recurring cycle of those unit fractions as 0.
Let L(n) denote the length of the recurring cycle of 1/n. You are given that L(n) for 3 ≤ n ≤ 1 000 000 equals 55535191115.
Let $L(n)$ denote the length of the recurring cycle of $\frac{1}{n}$. You are given that $\sum L(n)$ for $3 ≤ n ≤ 1\\,000\\,000$ equals $55\\,535\\,191\\,115$.
Find L(n) for 3 ≤ n ≤ 100 000 000
Find $\sum L(n)$ for $3 ≤ n ≤ 100\\,000\\,000$.
# --hints--
`euler417()` should return 446572970925740.
`reciprocalCyclesTwo()` should return `446572970925740`.
```js
assert.strictEqual(euler417(), 446572970925740);
assert.strictEqual(reciprocalCyclesTwo(), 446572970925740);
```
# --seed--
@ -33,12 +43,12 @@ assert.strictEqual(euler417(), 446572970925740);
## --seed-contents--
```js
function euler417() {
function reciprocalCyclesTwo() {
return true;
}
euler417();
reciprocalCyclesTwo();
```
# --solutions--

View File

@ -8,22 +8,23 @@ dashedName: problem-418-factorisation-triples
# --description--
Let n be a positive integer. An integer triple (a, b, c) is called a factorisation triple of n if: 1 ≤ a ≤ b ≤ c
Let $n$ be a positive integer. An integer triple ($a$, $b$, $c$) is called a factorisation triple of $n$ if:
a·b·c = n.
- $1 ≤ a ≤ b ≤ c$
- $a \times b \times c = n$.
Define f(n) to be a + b + c for the factorisation triple (a, b, c) of n which minimises c / a. One can show that this triple is unique.
Define $f(n)$ to be $a + b + c$ for the factorisation triple ($a$, $b$, $c$) of $n$ which minimises $\frac{c}{a}$. One can show that this triple is unique.
For example, f(165) = 19, f(100100) = 142 and f(20!) = 4034872.
For example, $f(165) = 19$, $f(100\\,100) = 142$ and $f(20!) = 4\\,034\\,872$.
Find f(43!).
Find $f(43!)$.
# --hints--
`euler418()` should return 1177163565297340400.
`factorisationTriples()` should return `1177163565297340400`.
```js
assert.strictEqual(euler418(), 1177163565297340400);
assert.strictEqual(factorisationTriples(), 1177163565297340400);
```
# --seed--
@ -31,12 +32,12 @@ assert.strictEqual(euler418(), 1177163565297340400);
## --seed-contents--
```js
function euler418() {
function factorisationTriples() {
return true;
}
euler418();
factorisationTriples();
```
# --solutions--

View File

@ -14,28 +14,35 @@ The sequence starts with 1 and all other members are obtained by describing the
It helps to do this out loud:
1 is 'one one' → 11
1 is 'one one' $→ 11$
11 is 'two ones' → 21
11 is 'two ones' $→ 21$
21 is 'one two and one one' → 1211
21 is 'one two and one one' $→ 1211$
1211 is 'one one, one two and two ones' → 111221
1211 is 'one one, one two and two ones' $→ 111221$
111221 is 'three ones, two twos and one one' → 312211
111221 is 'three ones, two twos and one one' $→ 312211$
...
Define A(n), B(n) and C(n) as the number of ones, twos and threes in the n'th element of the sequence respectively. One can verify that A(40) = 31254, B(40) = 20259 and C(40) = 11625.
Define $A(n)$, $B(n)$ and $C(n)$ as the number of ones, twos and threes in the $n$'th element of the sequence respectively. One can verify that $A(40) = 31\\,254$, $B(40) = 20\\,259$ and $C(40) = 11\\,625$.
Find A(n), B(n) and C(n) for n = 1012. Give your answer modulo 230 and separate your values for A, B and C by a comma. E.g. for n = 40 the answer would be 31254,20259,11625
Find $A(n)$, $B(n)$ and $C(n)$ for $n = {10}^{12}$. Give your answer modulo $2^{30}$ as a string and separate your values for $A$, $B$ and $C$ by a comma. E.g. for $n = 40$ the answer would be `31254,20259,11625`.
# --hints--
`euler419()` should return 998567458, 1046245404, 43363922.
`lookAndSaySequence()` should return a string.
```js
assert.strictEqual(euler419(), 998567458, 1046245404, 43363922);
assert(typeof lookAndSaySequence() === 'string');
```
`lookAndSaySequence()` should return the string `998567458,1046245404,43363922`.
```js
assert.strictEqual(lookAndSaySequence(), '998567458,1046245404,43363922');
```
# --seed--
@ -43,12 +50,12 @@ assert.strictEqual(euler419(), 998567458, 1046245404, 43363922);
## --seed-contents--
```js
function euler419() {
function lookAndSaySequence() {
return true;
}
euler419();
lookAndSaySequence();
```
# --solutions--

View File

@ -12,16 +12,31 @@ A positive integer matrix is a matrix whose elements are all positive integers.
Some positive integer matrices can be expressed as a square of a positive integer matrix in two different ways. Here is an example:
We define F(N) as the number of the 2x2 positive integer matrices which have a trace less than N and which can be expressed as a square of a positive integer matrix in two different ways. We can verify that F(50) = 7 and F(1000) = 1019.
$$\begin{pmatrix}
40 & 12 \\\\
48 & 40
\end{pmatrix} =
{\begin{pmatrix}
2 & 3 \\\\
12 & 2
\end{pmatrix}}^2 =
{\begin{pmatrix}
6 & 1 \\\\
4 & 6
\end{pmatrix}}^2$$
Find F(107).
We define $F(N)$ as the number of the 2x2 positive integer matrices which have a trace less than N and which can be expressed as a square of a positive integer matrix in two different ways.
We can verify that $F(50) = 7$ and $F(1000) = 1019$.
Find $F({10}^7)$.
# --hints--
`euler420()` should return 145159332.
`positiveIntegerMatrix()` should return `145159332`.
```js
assert.strictEqual(euler420(), 145159332);
assert.strictEqual(positiveIntegerMatrix(), 145159332);
```
# --seed--
@ -29,12 +44,12 @@ assert.strictEqual(euler420(), 145159332);
## --seed-contents--
```js
function euler420() {
function positiveIntegerMatrix() {
return true;
}
euler420();
positiveIntegerMatrix();
```
# --solutions--