fix: clean-up Project Euler 421-440 (#43047)

This commit is contained in:
gikf
2021-07-29 20:14:09 +02:00
committed by GitHub
parent 7bd08ae2ee
commit a9c11f7fe2
20 changed files with 306 additions and 189 deletions

View File

@ -8,20 +8,26 @@ dashedName: problem-421-prime-factors-of-n151
# --description--
Numbers of the form n15+1 are composite for every integer n > 1.
Numbers of the form $n^{15} + 1$ are composite for every integer $n > 1$.
For positive integers n and m let s(n,m) be defined as the sum of the distinct prime factors of n15+1 not exceeding m.
For positive integers $n$ and $m$ let $s(n, m)$ be defined as the sum of the distinct prime factors of $n^{15} + 1$ not exceeding $m$.
E.g. 215+1 = 3×3×11×331. So s(2,10) = 3 and s(2,1000) = 3+11+331 = 345.
E.g. $2^{15} + 1 = 3 × 3 × 11 × 331$.
Also 1015+1 = 7×11×13×211×241×2161×9091. So s(10,100) = 31 and s(10,1000) = 483. Find ∑ s(n,108) for 1 ≤ n ≤ 1011.
So $s(2, 10) = 3$ and $s(2, 1000) = 3 + 11 + 331 = 345$.
Also ${10}^{15} + 1 = 7 × 11 × 13 × 211 × 241 × 2161 × 9091$.
So $s(10, 100) = 31$ and $s(10, 1000) = 483$.
Find $\sum s(n, {10}^8)$ for $1 ≤ n ≤ {10}^{11}$.
# --hints--
`euler421()` should return 2304215802083466200.
`primeFactorsOfN15Plus1()` should return `2304215802083466200`.
```js
assert.strictEqual(euler421(), 2304215802083466200);
assert.strictEqual(primeFactorsOfN15Plus1(), 2304215802083466200);
```
# --seed--
@ -29,12 +35,12 @@ assert.strictEqual(euler421(), 2304215802083466200);
## --seed-contents--
```js
function euler421() {
function primeFactorsOfN15Plus1() {
return true;
}
euler421();
primeFactorsOfN15Plus1();
```
# --solutions--

View File

@ -8,22 +8,30 @@ dashedName: problem-422-sequence-of-points-on-a-hyperbola
# --description--
Let H be the hyperbola defined by the equation 12x2 + 7xy - 12y2 = 625.
Let $H$ be the hyperbola defined by the equation $12x^2 + 7xy - 12y^2 = 625$.
Next, define X as the point (7, 1). It can be seen that X is in H.
Next, define $X$ as the point (7, 1). It can be seen that $X$ is in $H$.
Now we define a sequence of points in H, {Pi : i ≥ 1}, as: P1 = (13, 61/4). P2 = (-43/6, -4). For i > 2, Pi is the unique point in H that is different from Pi-1 and such that line PiPi-1 is parallel to line Pi-2X. It can be shown that Pi is well-defined, and that its coordinates are always rational. You are given that P3 = (-19/2, -229/24), P4 = (1267/144, -37/12) and P7 = (17194218091/143327232, 274748766781/1719926784).
Now we define a sequence of points in $H, \\{P_i : i ≥ 1\\}$, as:
Find Pn for n = 1114 in the following format:If Pn = (a/b, c/d) where the fractions are in lowest terms and the denominators are positive, then the answer is (a + b + c + d) mod 1 000 000 007.
- $P_1 = (13, \frac{61}{4})$.
- $P_2 = (\frac{-43}{6}, -4)$.
- For $i > 2$, $P_i$ is the unique point in $H$ that is different from $P_{i - 1}$ and such that line $P_iP_{i - 1}$ is parallel to line $P_{i - 2}X$. It can be shown that $P_i$ is well-defined, and that its coordinates are always rational.
For n = 7, the answer would have been: 806236837.
<img class="img-responsive center-block" alt="animation showing defining points P_1 to P_6" src="https://cdn.freecodecamp.org/curriculum/project-euler/sequence-of-points-on-a-hyperbola.gif" style="background-color: white; padding: 10px;">
You are given that $P_3 = (\frac{-19}{2}, \frac{-229}{24})$, $P_4 = (\frac{1267}{144}, \frac{-37}{12})$ and $P_7 = (\frac{17\\,194\\,218\\,091}{143\\,327\\,232}, \frac{274\\,748\\,766\\,781}{1\\,719\\,926\\,784})$.
Find $P_n$ for $n = {11}^{14}$ in the following format: If $P_n = (\frac{a}{b}, \frac{c}{d})$ where the fractions are in lowest terms and the denominators are positive, then the answer is $(a + b + c + d)\bmod 1\\,000\\,000\\,007$.
For $n = 7$, the answer would have been: $806\\,236\\,837$.
# --hints--
`euler422()` should return 92060460.
`sequenceOfPointsOnHyperbola()` should return `92060460`.
```js
assert.strictEqual(euler422(), 92060460);
assert.strictEqual(sequenceOfPointsOnHyperbola(), 92060460);
```
# --seed--
@ -31,12 +39,12 @@ assert.strictEqual(euler422(), 92060460);
## --seed-contents--
```js
function euler422() {
function sequenceOfPointsOnHyperbola() {
return true;
}
euler422();
sequenceOfPointsOnHyperbola();
```
# --solutions--

View File

@ -8,26 +8,38 @@ dashedName: problem-423-consecutive-die-throws
# --description--
Let n be a positive integer.
Let $n$ be a positive integer.
A 6-sided die is thrown n times. Let c be the number of pairs of consecutive throws that give the same value.
A 6-sided die is thrown $n$ times. Let $c$ be the number of pairs of consecutive throws that give the same value.
For example, if n = 7 and the values of the die throws are (1,1,5,6,6,6,3), then the following pairs of consecutive throws give the same value: (1,1,5,6,6,6,3) (1,1,5,6,6,6,3) (1,1,5,6,6,6,3) Therefore, c = 3 for (1,1,5,6,6,6,3).
For example, if $n = 7$ and the values of the die throws are (1, 1, 5, 6, 6, 6, 3), then the following pairs of consecutive throws give the same value:
Define C(n) as the number of outcomes of throwing a 6-sided die n times such that c does not exceed π(n).1 For example, C(3) = 216, C(4) = 1290, C(11) = 361912500 and C(24) = 4727547363281250000.
$$\begin{align}
& (\underline{1}, \underline{1}, 5, 6, 6, 6, 3) \\\\
& (1, 1, 5, \underline{6}, \underline{6}, 6, 3) \\\\
& (1, 1, 5, 6, \underline{6}, \underline{6}, 3)
\end{align}$$
Define S(L) as ∑ C(n) for 1 ≤ n ≤ L. For example, S(50) mod 1 000 000 007 = 832833871.
Therefore, $c = 3$ for (1, 1, 5, 6, 6, 6, 3).
Find S(50 000 000) mod 1 000 000 007.
Define $C(n)$ as the number of outcomes of throwing a 6-sided die $n$ times such that $c$ does not exceed $π(n)$.<sup>1</sup>
1 π denotes the prime-counting function, i.e. π(n) is the number of primes ≤ n.
For example, $C(3) = 216$, $C(4) = 1290$, $C(11) = 361\\,912\\,500$ and $C(24) = 4\\,727\\,547\\,363\\,281\\,250\\,000$.
Define $S(L)$ as $\sum C(n)$ for $1 ≤ n ≤ L$.
For example, $S(50)\bmod 1\\,000\\,000\\,007 = 832\\,833\\,871$.
Find $S(50\\,000\\,000)\bmod 1\\,000\\,000\\,007$.
<sup>1</sup> $π$ denotes the prime-counting function, i.e. $π(n)$ is the number of primes $≤ n$.
# --hints--
`euler423()` should return 653972374.
`consecutiveDieThrows()` should return `653972374`.
```js
assert.strictEqual(euler423(), 653972374);
assert.strictEqual(consecutiveDieThrows(), 653972374);
```
# --seed--
@ -35,12 +47,12 @@ assert.strictEqual(euler423(), 653972374);
## --seed-contents--
```js
function euler423() {
function consecutiveDieThrows() {
return true;
}
euler423();
consecutiveDieThrows();
```
# --solutions--

File diff suppressed because one or more lines are too long

View File

@ -8,26 +8,29 @@ dashedName: problem-425-prime-connection
# --description--
Two positive numbers A and B are said to be connected (denoted by "A ↔ B") if one of these conditions holds:
Two positive numbers $A$ and $B$ are said to be connected (denoted by "$A ↔ B$") if one of these conditions holds:
(1) A and B have the same length and differ in exactly one digit; for example, 123 ↔ 173.
1. $A$ and $B$ have the same length and differ in exactly one digit; for example, $123 ↔ 173$.
2. Adding one digit to the left of $A$ (or $B$) makes $B$ (or $A$); for example, $23 ↔ 223$ and $123 ↔ 23$.
(2) Adding one digit to the left of A (or B) makes B (or A); for example, 23 ↔ 223 and 123 ↔ 23.
We call a prime $P$ a 2's relative if there exists a chain of connected primes between 2 and $P$ and no prime in the chain exceeds $P$.
We call a prime P a 2's relative if there exists a chain of connected primes between 2 and P and no prime in the chain exceeds P.
For example, 127 is a 2's relative. One of the possible chains is shown below:
For example, 127 is a 2's relative. One of the possible chains is shown below: 2 ↔ 3 ↔ 13 ↔ 113 ↔ 103 ↔ 107 ↔ 127 However, 11 and 103 are not 2's relatives.
$$2 ↔ 3 ↔ 13 ↔ 113 ↔ 103 ↔ 107 ↔ 127$$
Let F(N) be the sum of the primes ≤ N which are not 2's relatives. We can verify that F(103) = 431 and F(104) = 78728.
However, 11 and 103 are not 2's relatives.
Find F(107).
Let $F(N)$ be the sum of the primes $≤ N$ which are not 2's relatives. We can verify that $F({10}^3) = 431$ and $F({10}^4) = 78\\,728$.
Find $F({10}^7)$.
# --hints--
`euler425()` should return 46479497324.
`primeConnection()` should return `46479497324`.
```js
assert.strictEqual(euler425(), 46479497324);
assert.strictEqual(primeConnection(), 46479497324);
```
# --seed--
@ -35,12 +38,12 @@ assert.strictEqual(euler425(), 46479497324);
## --seed-contents--
```js
function euler425() {
function primeConnection() {
return true;
}
euler425();
primeConnection();
```
# --solutions--

View File

@ -14,20 +14,34 @@ A turn consists of moving each ball exactly once according to the following rule
After one turn the sequence (2, 2, 2, 1, 2) becomes (2, 2, 1, 2, 3) as can be seen below; note that we begin the new sequence starting at the first occupied box.
<img class="img-responsive center-block" alt="animation showing one complete turn from (2, 2, 2, 1, 2) to (2, 2, 1, 2, 3)" src="https://cdn.freecodecamp.org/curriculum/project-euler/box-ball-system-1.gif" style="background-color: white; padding: 10px;">
A system like this is called a Box-Ball System or BBS for short.
It can be shown that after a sufficient number of turns, the system evolves to a state where the consecutive numbers of occupied boxes is invariant. In the example below, the consecutive numbers of occupied boxes evolves to \[1, 2, 3]; we shall call this the final state.
It can be shown that after a sufficient number of turns, the system evolves to a state where the consecutive numbers of occupied boxes is invariant. In the example below, the consecutive numbers of occupied boxes evolves to [1, 2, 3]; we shall call this the final state.
We define the sequence {ti}:s0 = 290797 sk+1 = sk2 mod 50515093 tk = (sk mod 64) + 1
<img class="img-responsive center-block" alt="four turns from occupied boxes [2, 2, 2] to final state [1, 2, 3]" src="https://cdn.freecodecamp.org/curriculum/project-euler/box-ball-system-2.gif" style="background-color: white; padding: 10px;">
Starting from the initial configuration (t0, t1, …, t10), the final state becomes \[1, 3, 10, 24, 51, 75]. Starting from the initial configuration (t0, t1, …, t10 000 000), find the final state. Give as your answer the sum of the squares of the elements of the final state. For example, if the final state is \[1, 2, 3] then 14 ( = 12 + 22 + 32) is your answer.
We define the sequence $\\{t_i\\}$:
$$\begin{align}
& s_0 = 290\\,797 \\\\
& s_{k + 1} = {s_k}^2\bmod 50\\,515\\,093 \\\\
& t_k = (s_k\bmod 64) + 1
\end{align}$$
Starting from the initial configuration $(t_0, t_1, \ldots, t_{10})$, the final state becomes [1, 3, 10, 24, 51, 75].
Starting from the initial configuration $(t_0, t_1, \ldots, t_{10\\,000\\,000})$, find the final state.
Give as your answer the sum of the squares of the elements of the final state. For example, if the final state is [1, 2, 3] then $14 (= 1^2 + 2^2 + 3^2)$ is your answer.
# --hints--
`euler426()` should return 31591886008.
`boxBallSystem()` should return `31591886008`.
```js
assert.strictEqual(euler426(), 31591886008);
assert.strictEqual(boxBallSystem(), 31591886008);
```
# --seed--
@ -35,12 +49,12 @@ assert.strictEqual(euler426(), 31591886008);
## --seed-contents--
```js
function euler426() {
function boxBallSystem() {
return true;
}
euler426();
boxBallSystem();
```
# --solutions--

View File

@ -8,24 +8,24 @@ dashedName: problem-427-n-sequences
# --description--
A sequence of integers S = {si} is called an n-sequence if it has n elements and each element si satisfies 1 ≤ si ≤ n. Thus there are nn distinct n-sequences in total.
A sequence of integers $S = \\{s_i\\}$ is called an $n$-sequence if it has $n$ elements and each element $s_i$ satisfies $1 ≤ s_i ≤ n$. Thus there are $n^n$ distinct $n$-sequences in total.
For example, the sequence S = {1, 5, 5, 10, 7, 7, 7, 2, 3, 7} is a 10-sequence.
For example, the sequence $S = \\{1, 5, 5, 10, 7, 7, 7, 2, 3, 7\\}$ is a 10-sequence.
For any sequence S, let L(S) be the length of the longest contiguous subsequence of S with the same value. For example, for the given sequence S above, L(S) = 3, because of the three consecutive 7's.
For any sequence $S$, let $L(S)$ be the length of the longest contiguous subsequence of $S$ with the same value. For example, for the given sequence $S$ above, $L(S) = 3$, because of the three consecutive 7's.
Let f(n) = L(S) for all n-sequences S.
Let $f(n) = \sum L(S)$ for all $n$-sequences $S$.
For example, f(3) = 45, f(7) = 1403689 and f(11) = 481496895121.
For example, $f(3) = 45$, $f(7) = 1\\,403\\,689$ and $f(11) = 481\\,496\\,895\\,121$.
Find f(7 500 000) mod 1 000 000 009.
Find $f(7\\,500\\,000)\bmod 1\\,000\\,000\\,009$.
# --hints--
`euler427()` should return 97138867.
`nSequences()` should return `97138867`.
```js
assert.strictEqual(euler427(), 97138867);
assert.strictEqual(nSequences(), 97138867);
```
# --seed--
@ -33,12 +33,12 @@ assert.strictEqual(euler427(), 97138867);
## --seed-contents--
```js
function euler427() {
function nSequences() {
return true;
}
euler427();
nSequences();
```
# --solutions--

View File

@ -8,27 +8,32 @@ dashedName: problem-428-necklace-of-circles
# --description--
Let `a`, `b` and `c` be positive numbers.
Let $a$, $b$ and $c$ be positive numbers.
Let W, X, Y, Z be four collinear points where |WX| = `a`, |XY| = `b`, |YZ| = `c` and |WZ| = `a` + `b` + `c`.
Let $W$, $X$, $Y$, $Z$ be four collinear points where $|WX| = a$, $|XY| = b$, $|YZ| = c$ and $|WZ| = a + b + c$.
Let C<sub>in</sub> be the circle having the diameter XY.
Let $C_{\text{in}}$ be the circle having the diameter $XY$.
Let C<sub>out</sub> be the circle having the diameter WZ.
Let $C_{\text{out}}$ be the circle having the diameter $WZ$.
The triplet (`a`, `b`, `c`) is called a *necklace triplet* if you can place `k` ≥ 3 distinct circles C<sub>1</sub>, C<sub>2</sub>, ..., C<sub><var>k</var></sub> such that:
The triplet ($a$, $b$, $c$) is called a *necklace triplet* if you can place $k ≥ 3$ distinct circles $C_1, C_2, \ldots, C_k$ such that:
- $C_i$ has no common interior points with any $C_j$ for $1 ≤ i$, $j ≤ k$ and $i ≠ j$,
- $C_i$ is tangent to both $C_{\text{in}}$ and $C_{\text{out}}$ for $1 ≤ i ≤ k$,
- $C_i$ is tangent to $C_{i + 1}$ for $1 ≤ i &lt; k$, and
- $C_k$ is tangent to $C_1$.
<ul><li>C<sub><var>i</var></sub> has no common interior points with any C<sub><var>j</var></sub> for 1 ≤ <var>i</var>, <var>j</var><var>k</var> and <var>i</var><var>j</var>,</li><li>C<sub><var>i</var></sub> is tangent to both C<sub>in</sub> and C<sub>out</sub> for 1 ≤ <var>i</var><var>k</var>,</li><li>C<sub><var>i</var></sub> is tangent to C<sub><var>i</var>+1</sub> for 1 ≤ <var>i</var> &lt; <var>k</var>, and</li><li>C<sub><var>k</var></sub> is tangent to C<sub>1</sub>.</li></ul>
For example, (5, 5, 5) and (4, 3, 21) are necklace triplets, while it can be shown that (2, 2, 5) is not.
<img src="https://projecteuler.net/project/images/p428_necklace.png" alt="a visual representation of a necklace triplet">
Let T(`n`) be the number of necklace triplets (`a`, `b`, `c`) such that `a`, `b` and `c` are positive integers, and `b``n`. For example, T(1) = 9, T(20) = 732 and T(3000) = 438106.
<img class="img-responsive center-block" alt="a visual representation of a necklace triplet" src="https://cdn.freecodecamp.org/curriculum/project-euler/necklace-of-circles.png" style="background-color: white; padding: 10px;">
Find T(1 000 000 000).
Let $T(n)$ be the number of necklace triplets $(a, b, c)$ such that $a$, $b$ and $c$ are positive integers, and $b ≤ n$. For example, $T(1) = 9$, $T(20) = 732$ and $T(3\\,000) = 438\\,106$.
Find $T(1\\,000\\,000\\,000)$.
# --hints--
`necklace(1000000000)` should return 747215561862.
`necklace(1000000000)` should return `747215561862`.
```js
assert.strictEqual(necklace(1000000000), 747215561862);

View File

@ -8,22 +8,22 @@ dashedName: problem-429-sum-of-squares-of-unitary-divisors
# --description--
A unitary divisor d of a number n is a divisor of n that has the property gcd(d, n/d) = 1.
A unitary divisor $d$ of a number $n$ is a divisor of $n$ that has the property $gcd(d, \frac{n}{d}) = 1$.
The unitary divisors of 4! = 24 are 1, 3, 8 and 24.
The unitary divisors of $4! = 24$ are 1, 3, 8 and 24.
The sum of their squares is 12 + 32 + 82 + 242 = 650.
The sum of their squares is $12 + 32 + 82 + 242 = 650$.
Let S(n) represent the sum of the squares of the unitary divisors of n. Thus S(4!)=650.
Let $S(n)$ represent the sum of the squares of the unitary divisors of $n$. Thus $S(4!) = 650$.
Find S(100 000 000!) modulo 1 000 000 009.
Find $S(100\\,000\\,000!)$ modulo $1\\,000\\,000\\,009$.
# --hints--
`euler429()` should return 98792821.
`sumSquaresOfUnitaryDivisors()` should return `98792821`.
```js
assert.strictEqual(euler429(), 98792821);
assert.strictEqual(sumSquaresOfUnitaryDivisors(), 98792821);
```
# --seed--
@ -31,12 +31,12 @@ assert.strictEqual(euler429(), 98792821);
## --seed-contents--
```js
function euler429() {
function sumSquaresOfUnitaryDivisors() {
return true;
}
euler429();
sumSquaresOfUnitaryDivisors();
```
# --solutions--

View File

@ -8,24 +8,26 @@ dashedName: problem-430-range-flips
# --description--
N disks are placed in a row, indexed 1 to N from left to right.
$N$ disks are placed in a row, indexed 1 to $N$ from left to right.
Each disk has a black side and white side. Initially all disks show their white side.
At each turn, two, not necessarily distinct, integers A and B between 1 and N (inclusive) are chosen uniformly at random. All disks with an index from A to B (inclusive) are flipped.
At each turn, two, not necessarily distinct, integers $A$ and $B$ between 1 and $N$ (inclusive) are chosen uniformly at random. All disks with an index from $A$ to $B$ (inclusive) are flipped.
The following example shows the case N = 8. At the first turn A = 5 and B = 2, and at the second turn A = 4 and B = 6.
The following example shows the case $N = 8$. At the first turn $A = 5$ and $B = 2$, and at the second turn $A = 4$ and $B = 6$.
Let E(N, M) be the expected number of disks that show their white side after M turns. We can verify that E(3, 1) = 10/9, E(3, 2) = 5/3, E(10, 4) ≈ 5.157 and E(100, 10) ≈ 51.893.
<img class="img-responsive center-block" alt="example for N = 8, with first turn A = 5 and B = 2, and second turn A = 4 and B = 6" src="https://cdn.freecodecamp.org/curriculum/project-euler/range-flips.gif" style="background-color: white; padding: 10px;">
Find E(1010, 4000). Give your answer rounded to 2 decimal places behind the decimal point.
Let $E(N, M)$ be the expected number of disks that show their white side after $M$ turns. We can verify that $E(3, 1) = \frac{10}{9}$, $E(3, 2) = \frac{5}{3}$, $E(10, 4) ≈ 5.157$ and $E(100, 10) ≈ 51.893$.
Find $E({10}^{10}, 4000)$. Give your answer rounded to 2 decimal places behind the decimal point.
# --hints--
`euler430()` should return 5000624921.38.
`rangeFlips()` should return `5000624921.38`.
```js
assert.strictEqual(euler430(), 5000624921.38);
assert.strictEqual(rangeFlips(), 5000624921.38);
```
# --seed--
@ -33,12 +35,12 @@ assert.strictEqual(euler430(), 5000624921.38);
## --seed-contents--
```js
function euler430() {
function rangeFlips() {
return true;
}
euler430();
rangeFlips();
```
# --solutions--

View File

@ -10,20 +10,22 @@ dashedName: problem-431-square-space-silo
Fred the farmer arranges to have a new storage silo installed on his farm and having an obsession for all things square he is absolutely devastated when he discovers that it is circular. Quentin, the representative from the company that installed the silo, explains that they only manufacture cylindrical silos, but he points out that it is resting on a square base. Fred is not amused and insists that it is removed from his property.
Quick thinking Quentin explains that when granular materials are delivered from above a conical slope is formed and the natural angle made with the horizontal is called the angle of repose. For example if the angle of repose, $\\alpha = 30$ degrees, and grain is delivered at the centre of the silo then a perfect cone will form towards the top of the cylinder. In the case of this silo, which has a diameter of 6m, the amount of space wasted would be approximately 32.648388556 m3. However, if grain is delivered at a point on the top which has a horizontal distance of $x$ metres from the centre then a cone with a strangely curved and sloping base is formed. He shows Fred a picture.
Quick thinking Quentin explains that when granular materials are delivered from above a conical slope is formed and the natural angle made with the horizontal is called the angle of repose. For example if the angle of repose, $\alpha = 30°$, and grain is delivered at the centre of the silo then a perfect cone will form towards the top of the cylinder. In the case of this silo, which has a diameter of 6m, the amount of space wasted would be approximately 32.648388556 m<sup>3</sup>. However, if grain is delivered at a point on the top which has a horizontal distance of $x$ metres from the centre then a cone with a strangely curved and sloping base is formed. He shows Fred a picture.
We shall let the amount of space wasted in cubic metres be given by $V(x)$. If $x = 1.114785284$, which happens to have three squared decimal places, then the amount of space wasted, $V(1.114785284) \\approx 36$. Given the range of possible solutions to this problem there is exactly one other option: $V(2.511167869) \\approx 49$. It would be like knowing that the square is king of the silo, sitting in splendid glory on top of your grain.
<img class="img-responsive center-block" alt="image presenting forming of the perfect cone towards the top of the cylinder" src="https://cdn.freecodecamp.org/curriculum/project-euler/square-space-silo.png" style="background-color: white; padding: 10px;">
Fred's eyes light up with delight at this elegant resolution, but on closer inspection of Quentin's drawings and calculations his happiness turns to despondency once more. Fred points out to Quentin that it's the radius of the silo that is 6 metres, not the diameter, and the angle of repose for his grain is 40 degrees. However, if Quentin can find a set of solutions for this particular silo then he will be more than happy to keep it.
We shall let the amount of space wasted in cubic metres be given by $V(x)$. If $x = 1.114\\,785\\,284$, which happens to have three squared decimal places, then the amount of space wasted, $V(1.114\\,785\\,284) \approx 36$. Given the range of possible solutions to this problem there is exactly one other option: $V(2.511\\,167\\,869) \approx 49$. It would be like knowing that the square is king of the silo, sitting in splendid glory on top of your grain.
If Quick thinking Quentin is to satisfy frustratingly fussy Fred the farmer's appetite for all things square then determine the values of $x$ for all possible square space wastage options and calculate $\\sum x$ correct to 9 decimal places.
Fred's eyes light up with delight at this elegant resolution, but on closer inspection of Quentin's drawings and calculations his happiness turns to despondency once more. Fred points out to Quentin that it's the radius of the silo that is 6 metres, not the diameter, and the angle of repose for his grain is 40­°. However, if Quentin can find a set of solutions for this particular silo then he will be more than happy to keep it.
If Quick thinking Quentin is to satisfy frustratingly fussy Fred the farmer's appetite for all things square then determine the values of $x$ for all possible square space wastage options and calculate $\sum x$ correct to 9 decimal places.
# --hints--
`euler431()` should return 23.386029052.
`squareSpaceSilo()` should return `23.386029052`.
```js
assert.strictEqual(euler431(), 23.386029052);
assert.strictEqual(squareSpaceSilo(), 23.386029052);
```
# --seed--
@ -31,12 +33,12 @@ assert.strictEqual(euler431(), 23.386029052);
## --seed-contents--
```js
function euler431() {
function squareSpaceSilo() {
return true;
}
euler431();
squareSpaceSilo();
```
# --solutions--

View File

@ -8,18 +8,18 @@ dashedName: problem-432-totient-sum
# --description--
Let S(n,m) = φ(n × i) for 1 ≤ i ≤ m. (φ is Euler's totient function)
Let $S(n, m) = \sum φ(n × i)$ for $1 ≤ i ≤ m$. ($φ$ is Euler's totient function)
You are given that S(510510,106 )= 45480596821125120.
You are given that $S(510\\,510, {10}^6) = 45\\,480\\,596\\,821\\,125\\,120$.
Find S(510510,1011). Give the last 9 digits of your answer.
Find $S(510\\,510, {10}^{11})$. Give the last 9 digits of your answer.
# --hints--
`euler432()` should return 754862080.
`totientSum()` should return `754862080`.
```js
assert.strictEqual(euler432(), 754862080);
assert.strictEqual(totientSum(), 754862080);
```
# --seed--
@ -27,12 +27,12 @@ assert.strictEqual(euler432(), 754862080);
## --seed-contents--
```js
function euler432() {
function totientSum() {
return true;
}
euler432();
totientSum();
```
# --solutions--

View File

@ -8,22 +8,29 @@ dashedName: problem-433-steps-in-euclids-algorithm
# --description--
Let E(x0, y0) be the number of steps it takes to determine the greatest common divisor of x0 and y0 with Euclid's algorithm. More formally:x1 = y0, y1 = x0 mod y0xn = yn-1, yn = xn-1 mod yn-1
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:
E(x0, y0) is the smallest n such that yn = 0.
$$\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}$$
We have E(1,1) = 1, E(10,6) = 3 and E(6,10) = 4.
$E(x_0, y_0)$ is the smallest $n$ such that $y_n = 0$.
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) = 39826.
We have $E(1, 1) = 1$, $E(10, 6) = 3$ and $E(6, 10) = 4$.
Find S(5·106).
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)$.
# --hints--
`euler433()` should return 326624372659664.
`stepsInEuclidsAlgorithm()` should return `326624372659664`.
```js
assert.strictEqual(euler433(), 326624372659664);
assert.strictEqual(stepsInEuclidsAlgorithm(), 326624372659664);
```
# --seed--
@ -31,12 +38,12 @@ assert.strictEqual(euler433(), 326624372659664);
## --seed-contents--
```js
function euler433() {
function stepsInEuclidsAlgorithm() {
return true;
}
euler433();
stepsInEuclidsAlgorithm();
```
# --solutions--

View File

@ -18,18 +18,32 @@ A rigid graph is an embedding of a graph which is not flexible.
Informally, a graph is rigid if by replacing the vertices with fully rotating hinges and the edges with rods that are unbending and inelastic, no parts of the graph can be moved independently from the rest of the graph.
The grid graphs embedded in the Euclidean plane are not rigid, as the following animation demonstrates: However, one can make them rigid by adding diagonal edges to the cells. For example, for the 2x3 grid graph, there are 19 ways to make the graph rigid: Note that for the purposes of this problem, we do not consider changing the orientation of a diagonal edge or adding both diagonal edges to a cell as a different way of making a grid graph rigid.
The grid graphs embedded in the Euclidean plane are not rigid, as the following animation demonstrates:
Let R(m,n) be the number of ways to make the m × n grid graph rigid. E.g. R(2,3) = 19 and R(5,5) = 23679901
<img class="img-responsive center-block" alt="animation showing grid graphs are not rigid in Euclidean plane" src="https://cdn.freecodecamp.org/curriculum/project-euler/rigid-graphs-1.gif" style="background-color: white; padding: 10px;">
Define S(N) as ∑R(i,j) for 1 ≤ i, j ≤ N. E.g. S(5) = 25021721. Find S(100), give your answer modulo 1000000033
However, one can make them rigid by adding diagonal edges to the cells. For example, for the 2x3 grid graph, there are 19 ways to make the graph rigid:
<img class="img-responsive center-block" alt="19 ways to make 2x3 grid graph rigid" src="https://cdn.freecodecamp.org/curriculum/project-euler/rigid-graphs-2.png" style="background-color: white; padding: 10px;">
Note that for the purposes of this problem, we do not consider changing the orientation of a diagonal edge or adding both diagonal edges to a cell as a different way of making a grid graph rigid.
Let $R(m, n)$ be the number of ways to make the $m × n$ grid graph rigid.
E.g. $R(2, 3) = 19$ and $R(5, 5) = 23\\,679\\,901$.
Define $S(N)$ as $\sum R(i, j)$ for $1 ≤ i$, $j ≤ N$.
E.g. $S(5) = 25\\,021\\,721$.
Find $S(100)$, give your answer modulo $1\\,000\\,000\\,033$.
# --hints--
`euler434()` should return 863253606.
`rigidGraphs()` should return `863253606`.
```js
assert.strictEqual(euler434(), 863253606);
assert.strictEqual(rigidGraphs(), 863253606);
```
# --seed--
@ -37,12 +51,12 @@ assert.strictEqual(euler434(), 863253606);
## --seed-contents--
```js
function euler434() {
function rigidGraphs() {
return true;
}
euler434();
rigidGraphs();
```
# --solutions--

View File

@ -8,20 +8,20 @@ dashedName: problem-435-polynomials-of-fibonacci-numbers
# --description--
The Fibonacci numbers {fn, n ≥ 0} are defined recursively as fn = fn-1 + fn-2 with base cases f0 = 0 and f1 = 1.
The Fibonacci numbers $\\{f_n, n ≥ 0\\}$ are defined recursively as $f_n = f_{n - 1} + f_{n - 2}$ with base cases $f_0 = 0$ and $f_1 = 1$.
Define the polynomials {Fn, n ≥ 0} as Fn(x) = ∑fixi for 0 ≤ i ≤ n.
Define the polynomials $\\{F_n, n ≥ 0\\}$ as $F_n(x) = \displaystyle\sum_{i = 0}^n f_ix^i$.
For example, F7(x) = x + x2 + 2x3 + 3x4 + 5x5 + 8x6 + 13x7, and F7(11) = 268357683.
For example, $F_7(x) = x + x^2 + 2x^3 + 3x^4 + 5x^5 + 8x^6 + 13x^7$, and $F_7(11) = 268\\,357\\,683$.
Let n = 1015. Find the sum \[∑0≤x≤100 Fn(x)] mod 1307674368000 (= 15!).
Let $n = {10}^{15}$. Find the sum $\displaystyle\sum_{x = 0}^{100} F_n(x)$ and give your answer modulo $1\\,307\\,674\\,368\\,000 \\, (= 15!)$.
# --hints--
`euler435()` should return 252541322550.
`polynomialsOfFibonacciNumbers()` should return `252541322550`.
```js
assert.strictEqual(euler435(), 252541322550);
assert.strictEqual(polynomialsOfFibonacciNumbers(), 252541322550);
```
# --seed--
@ -29,12 +29,12 @@ assert.strictEqual(euler435(), 252541322550);
## --seed-contents--
```js
function euler435() {
function polynomialsOfFibonacciNumbers() {
return true;
}
euler435();
polynomialsOfFibonacciNumbers();
```
# --solutions--

View File

@ -14,24 +14,26 @@ She suggests they play a game of chance to determine who will wash the dishes.
For this game, they shall use a generator of independent random numbers uniformly distributed between 0 and 1.
The game starts with S = 0.
The game starts with $S = 0$.
The first player, Louise, adds to S different random numbers from the generator until S > 1 and records her last random number 'x'.
The first player, Louise, adds to $S$ different random numbers from the generator until $S > 1$ and records her last random number '$x$'.
The second player, Julie, continues adding to S different random numbers from the generator until S > 2 and records her last random number 'y'.
The second player, Julie, continues adding to $S$ different random numbers from the generator until $S > 2$ and records her last random number '$y$'.
The player with the highest number wins and the loser washes the dishes, i.e. if y > x the second player wins.
The player with the highest number wins and the loser washes the dishes, i.e. if $y > x$ the second player wins.
For example, if the first player draws 0.62 and 0.44, the first player turn ends since 0.62+0.44 > 1 and x = 0.44. If the second players draws 0.1, 0.27 and 0.91, the second player turn ends since 0.62+0.44+0.1+0.27+0.91 > 2 and y = 0.91. Since y > x, the second player wins.
For example, if the first player draws 0.62 and 0.44, the first player turn ends since $0.62 + 0.44 > 1$ and $x = 0.44$. If the second players draws 0.1, 0.27 and 0.91, the second player turn ends since $0.62 + 0.44 + 0.1 + 0.27 + 0.91 > 2$ and $y = 0.91$. Since $y > x$, the second player wins.
Louise thinks about it for a second, and objects: "That's not fair". What is the probability that the second player wins? Give your answer rounded to 10 places behind the decimal point in the form 0.abcdefghij
Louise thinks about it for a second, and objects: "That's not fair".
What is the probability that the second player wins? Give your answer rounded to 10 places behind the decimal point in the form 0.abcdefghij
# --hints--
`euler436()` should return 0.5276662759.
`unfairWager()` should return `0.5276662759`.
```js
assert.strictEqual(euler436(), 0.5276662759);
assert.strictEqual(unfairWager(), 0.5276662759);
```
# --seed--
@ -39,12 +41,12 @@ assert.strictEqual(euler436(), 0.5276662759);
## --seed-contents--
```js
function euler436() {
function unfairWager() {
return true;
}
euler436();
unfairWager();
```
# --solutions--

View File

@ -8,7 +8,7 @@ dashedName: problem-437-fibonacci-primitive-roots
# --description--
When we calculate 8n modulo 11 for n=0 to 9 we get: 1, 8, 9, 6, 4, 10, 3, 2, 5, 7.
When we calculate $8^n$ modulo 11 for $n = 0$ to 9 we get: 1, 8, 9, 6, 4, 10, 3, 2, 5, 7.
As we see all possible values from 1 to 10 occur. So 8 is a primitive root of 11.
@ -16,32 +16,30 @@ But there is more:
If we take a closer look we see:
1+8=9
$$\begin{align}
& 1 + 8 = 9 \\\\
& 8 + 9 = 17 ≡ 6\bmod 11 \\\\
& 9 + 6 = 15 ≡ 4\bmod 11 \\\\
& 6 + 4 = 10 \\\\
& 4 + 10 = 14 ≡ 3\bmod 11 \\\\
& 10 + 3 = 13 ≡ 2\bmod 11 \\\\
& 3 + 2 = 5 \\\\
& 2 + 5 = 7 \\\\
& 5 + 7 = 12 ≡ 1\bmod 11.
\end{align}$$
8+9=17≡6 mod 11
So the powers of 8 mod 11 are cyclic with period 10, and $8^n + 8^{n + 1} ≡ 8^{n + 2} (\text{mod } 11)$. 8 is called a Fibonacci primitive root of 11.
9+6=15≡4 mod 11
Not every prime has a Fibonacci primitive root. There are 323 primes less than 10000 with one or more Fibonacci primitive roots and the sum of these primes is 1480491.
6+4=10
4+10=14≡3 mod 11
10+3=13≡2 mod 11
3+2=5
2+5=7
5+7=12≡1 mod 11.
So the powers of 8 mod 11 are cyclic with period 10, and 8n + 8n+1 ≡ 8n+2 (mod 11). 8 is called a Fibonacci primitive root of 11. Not every prime has a Fibonacci primitive root. There are 323 primes less than 10000 with one or more Fibonacci primitive roots and the sum of these primes is 1480491. Find the sum of the primes less than 100,000,000 with at least one Fibonacci primitive root.
Find the sum of the primes less than $100\\,000\\,000$ with at least one Fibonacci primitive root.
# --hints--
`euler437()` should return 74204709657207.
`fibonacciPrimitiveRoots()` should return `74204709657207`.
```js
assert.strictEqual(euler437(), 74204709657207);
assert.strictEqual(fibonacciPrimitiveRoots(), 74204709657207);
```
# --seed--
@ -49,12 +47,12 @@ assert.strictEqual(euler437(), 74204709657207);
## --seed-contents--
```js
function euler437() {
function fibonacciPrimitiveRoots() {
return true;
}
euler437();
fibonacciPrimitiveRoots();
```
# --solutions--

View File

@ -8,20 +8,27 @@ dashedName: problem-438-integer-part-of-polynomial-equations-solutions
# --description--
For an n-tuple of integers t = (a1, ..., an), let (x1, ..., xn) be the solutions of the polynomial equation xn + a1xn-1 + a2xn-2 + ... + an-1x + an = 0.
For an $n$-tuple of integers $t = (a_1, \ldots, a_n)$, let $(x_1, \ldots, x_n)$ be the solutions of the polynomial equation $x^n + a_1x^{n - 1} + a_2x^{n - 2} + \ldots + a_{n - 1}x + a_n = 0$.
Consider the following two conditions: x1, ..., xn are all real. If x1, ..., xn are sorted, ⌊xi⌋ = i for 1 ≤ i ≤ n. (⌊·⌋: floor function.)
Consider the following two conditions:
In the case of n = 4, there are 12 n-tuples of integers which satisfy both conditions. We define S(t) as the sum of the absolute values of the integers in t. For n = 4 we can verify that ∑S(t) = 2087 for all n-tuples t which satisfy both conditions.
- $x_1, \ldots, x_n$ are all real.
- If $x_1, ..., x_n$ are sorted, $⌊x_i⌋ = i$ for $1 ≤ i ≤ n$. ($⌊·⌋:$ floor function.)
Find ∑S(t) for n = 7.
In the case of $n = 4$, there are 12 $n$-tuples of integers which satisfy both conditions.
We define $S(t)$ as the sum of the absolute values of the integers in $t$.
For $n = 4$ we can verify that $\sum S(t) = 2087$ for all $n$-tuples t which satisfy both conditions.
Find $\sum S(t)$ for $n = 7$.
# --hints--
`euler438()` should return 2046409616809.
`polynomialIntegerPart()` should return `2046409616809`.
```js
assert.strictEqual(euler438(), 2046409616809);
assert.strictEqual(polynomialIntegerPart(), 2046409616809);
```
# --seed--
@ -29,12 +36,12 @@ assert.strictEqual(euler438(), 2046409616809);
## --seed-contents--
```js
function euler438() {
function polynomialIntegerPart() {
return true;
}
euler438();
polynomialIntegerPart();
```
# --solutions--

View File

@ -8,20 +8,22 @@ dashedName: problem-439-sum-of-sum-of-divisors
# --description--
Let d(k) be the sum of all divisors of k.
Let $d(k)$ be the sum of all divisors of $k$.
We define the function S(N) = ∑1≤i≤N ∑1≤j≤Nd(i·j).
We define the function $S(N) = \sum_{i = 1}^N \sum_{j = 1}^N d(i \times j)$.
For example, S(3) = d(1) + d(2) + d(3) + d(2) + d(4) + d(6) + d(3) + d(6) + d(9) = 59.
For example, $S(3) = d(1) + d(2) + d(3) + d(2) + d(4) + d(6) + d(3) + d(6) + d(9) = 59$.
You are given that S(103) = 563576517282 and S(105) mod 109 = 215766508. Find S(1011) mod 109.
You are given that $S({10}^3) = 563\\,576\\,517\\,282$ and $S({10}^5)\bmod {10}^9 = 215\\,766\\,508$.
Find $S({10}^{11})\bmod {10}^9$.
# --hints--
`euler439()` should return 968697378.
`sumOfSumOfDivisors()` should return `968697378`.
```js
assert.strictEqual(euler439(), 968697378);
assert.strictEqual(sumOfSumOfDivisors(), 968697378);
```
# --seed--
@ -29,12 +31,12 @@ assert.strictEqual(euler439(), 968697378);
## --seed-contents--
```js
function euler439() {
function sumOfSumOfDivisors() {
return true;
}
euler439();
sumOfSumOfDivisors();
```
# --solutions--

View File

@ -8,24 +8,36 @@ dashedName: problem-440-gcd-and-tiling
# --description--
We want to tile a board of length n and height 1 completely, with either 1 × 2 blocks or 1 × 1 blocks with a single decimal digit on top:
We want to tile a board of length $n$ and height 1 completely, with either 1 × 2 blocks or 1 × 1 blocks with a single decimal digit on top:
For example, here are some of the ways to tile a board of length n = 8:
<img class="img-responsive center-block" alt="ten blocks 1x1 with single decimal digit on top, and 1x2 block" src="https://cdn.freecodecamp.org/curriculum/project-euler/gcd-and-tiling-1.png" style="background-color: white; padding: 10px;">
Let T(n) be the number of ways to tile a board of length n as described above.
For example, here are some of the ways to tile a board of length $n = 8$:
For example, T(1) = 10 and T(2) = 101.
<img class="img-responsive center-block" alt="examples of ways to tile a board of length n = 8" src="https://cdn.freecodecamp.org/curriculum/project-euler/gcd-and-tiling-2.png" style="background-color: white; padding: 10px;">
Let S(L) be the triple sum ∑a,b,c gcd(T(ca), T(cb)) for 1 ≤ a, b, c ≤ L. For example: S(2) = 10444 S(3) = 1292115238446807016106539989 S(4) mod 987 898 789 = 670616280.
Let $T(n)$ be the number of ways to tile a board of length $n$ as described above.
Find S(2000) mod 987 898 789.
For example, $T(1) = 10$ and $T(2) = 101$.
Let $S(L)$ be the triple sum $\sum_{a, b, c} gcd(T(c^a), T(c^b))$ for $1 ≤ a, b, c ≤ L$.
For example:
$$\begin{align}
& S(2) = 10\\,444 \\\\
& S(3) = 1\\,292\\,115\\,238\\,446\\,807\\,016\\,106\\,539\\,989 \\\\
& S(4)\bmod 987\\,898\\,789 = 670\\,616\\,280.
\end{align}$$
Find $S(2000)\bmod 987\\,898\\,789$.
# --hints--
`euler440()` should return 970746056.
`gcdAndTiling()` should return `970746056`.
```js
assert.strictEqual(euler440(), 970746056);
assert.strictEqual(gcdAndTiling(), 970746056);
```
# --seed--
@ -33,12 +45,12 @@ assert.strictEqual(euler440(), 970746056);
## --seed-contents--
```js
function euler440() {
function gcdAndTiling() {
return true;
}
euler440();
gcdAndTiling();
```
# --solutions--