fix(curriculum): clean-up Project Euler 441-460 (#43068)

* fix: clean-up Project Euler 441-460

* fix: corrections from review

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
This commit is contained in:
gikf
2021-07-30 17:20:31 +02:00
committed by GitHub
parent d269909faa
commit a2b2ef3f75
20 changed files with 267 additions and 185 deletions

View File

@ -8,20 +8,24 @@ dashedName: problem-441-the-inverse-summation-of-coprime-couples
# --description--
For an integer M, we define R(M) as the sum of 1/(p·q) for all the integer pairs p and q which satisfy all of these conditions:
For an integer $M$, we define $R(M)$ as the sum of $\frac{1}{p·q}$ for all the integer pairs $p$ and $q$ which satisfy all of these conditions:
1 ≤ p &lt; q ≤ M p + q ≥ M p and q are coprime.
- $1 ≤ p &lt; q ≤ M$
- $p + q ≥ M$
- $p$ and $q$ are coprime.
We also define S(N) as the sum of R(i) for 2 ≤ i ≤ N. We can verify that S(2) = R(2) = 1/2, S(10) ≈ 6.9147 and S(100) ≈ 58.2962.
We also define $S(N)$ as the sum of $R(i)$ for $2 ≤ i ≤ N$.
Find S(107). Give your answer rounded to four decimal places.
We can verify that $S(2) = R(2) = \frac{1}{2}$, $S(10) ≈ 6.9147$ and $S(100) ≈ 58.2962$.
Find $S({10}^7)$. Give your answer rounded to four decimal places.
# --hints--
`euler441()` should return 5000088.8395.
`inverseSummationCoprimeCouples()` should return `5000088.8395`.
```js
assert.strictEqual(euler441(), 5000088.8395);
assert.strictEqual(inverseSummationCoprimeCouples(), 5000088.8395);
```
# --seed--
@ -29,12 +33,12 @@ assert.strictEqual(euler441(), 5000088.8395);
## --seed-contents--
```js
function euler441() {
function inverseSummationCoprimeCouples() {
return true;
}
euler441();
inverseSummationCoprimeCouples();
```
# --solutions--

View File

@ -12,16 +12,16 @@ An integer is called eleven-free if its decimal expansion does not contain any s
For example, 2404 and 13431 are eleven-free, while 911 and 4121331 are not.
Let E(n) be the nth positive eleven-free integer. For example, E(3) = 3, E(200) = 213 and E(500 000) = 531563.
Let $E(n)$ be the $n$th positive eleven-free integer. For example, $E(3) = 3$, $E(200) = 213$ and $E(500\\,000) = 531\\,563$.
Find E(1018).
Find $E({10}^{18})$.
# --hints--
`euler442()` should return 1295552661530920200.
`elevenFreeIntegers()` should return `1295552661530920200`.
```js
assert.strictEqual(euler442(), 1295552661530920200);
assert.strictEqual(elevenFreeIntegers(), 1295552661530920200);
```
# --seed--
@ -29,12 +29,12 @@ assert.strictEqual(euler442(), 1295552661530920200);
## --seed-contents--
```js
function euler442() {
function elevenFreeIntegers() {
return true;
}
euler442();
elevenFreeIntegers();
```
# --solutions--

View File

@ -8,24 +8,30 @@ dashedName: problem-443-gcd-sequence
# --description--
Let g(n) be a sequence defined as follows: g(4) = 13, g(n) = g(n-1) + gcd(n, g(n-1)) for n > 4.
Let $g(n)$ be a sequence defined as follows:
$$\begin{align}
& g(4) = 13, \\\\
& g(n) = g(n-1) + gcd(n, g(n - 1)) \text{ for } n > 4.
\end{align}$$
The first few values are:
n 4567891011121314151617181920... g(n) 1314161718272829303132333451545560...
$$\begin{array}{l}
n & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 & 20 & \ldots \\\\
g(n) & 13 & 14 & 16 & 17 & 18 & 27 & 28 & 29 & 30 & 31 & 32 & 33 & 34 & 51 & 54 & 55 & 60 & \ldots
\end{array}$$
<!-- TODO Use MathJax -->
You are given that $g(1\\,000) = 2\\,524$ and $g(1\\,000\\,000) = 2\\,624\\,152$.
You are given that g(1 000) = 2524 and g(1 000 000) = 2624152.
Find g(1015).
Find $g({10}^{15})$.
# --hints--
`euler443()` should return 2744233049300770.
`gcdSequence()` should return `2744233049300770`.
```js
assert.strictEqual(euler443(), 2744233049300770);
assert.strictEqual(gcdSequence(), 2744233049300770);
```
# --seed--
@ -33,12 +39,12 @@ assert.strictEqual(euler443(), 2744233049300770);
## --seed-contents--
```js
function euler443() {
function gcdSequence() {
return true;
}
euler443();
gcdSequence();
```
# --solutions--

View File

@ -8,7 +8,7 @@ dashedName: problem-444-the-roundtable-lottery
# --description--
A group of p people decide to sit down at a round table and play a lottery-ticket trading game. Each person starts off with a randomly-assigned, unscratched lottery ticket. Each ticket, when scratched, reveals a whole-pound prize ranging anywhere from £1 to £p, with no two tickets alike. The goal of the game is for each person to maximize his ticket winnings upon leaving the game.
A group of $p$ people decide to sit down at a round table and play a lottery-ticket trading game. Each person starts off with a randomly-assigned, unscratched lottery ticket. Each ticket, when scratched, reveals a whole-pound prize ranging anywhere from £1 to £$p$, with no two tickets alike. The goal of the game is for each person to maximize his ticket winnings upon leaving the game.
An arbitrary person is chosen to be the first player. Going around the table, each player has only one of two options:
@ -19,18 +19,26 @@ The game ends once all tickets have been scratched. All players still remaining
Assume that each player uses the optimal strategy for maximizing the expected value of his ticket winnings.
Let E(p) represent the expected number of players left at the table when the game ends in a game consisting of p players (e.g. E(111) = 5.2912 when rounded to 5 significant digits).
Let $E(p)$ represent the expected number of players left at the table when the game ends in a game consisting of $p$ players (e.g. $E(111) = 5.2912$ when rounded to 5 significant digits).
Let S1(N) = E(p) Let Sk(N) = Sk-1(p) for k > 1
Let $S_1(N) = \displaystyle\sum_{p = 1}^N E(p)$.
Find S20(1014) and write the answer in scientific notation rounded to 10 significant digits. Use a lowercase e to separate mantissa and exponent (e.g. S3(100) = 5.983679014e5).
Let $S_k(N) = \displaystyle\sum_{p = 1}^N S_{k - 1}(p)$ for $k > 1$.
Find $S_{20}({10}^{14})$ and write the answer as a string in scientific notation rounded to 10 significant digits. Use a lowercase `e` to separate mantissa and exponent. For example, the answer for $S_3(100)$ would be `5.983679014e5`.
# --hints--
`euler444()` should return 1.200856722e+263.
`roundtableLottery()` should return a string.
```js
assert.strictEqual(euler444(), 1.200856722e263);
assert(typeof roundtableLottery() === 'string');
```
`roundtableLottery()` should return the string `1.200856722e263`.
```js
assert.strictEqual(roundtableLottery(), '1.200856722e263');
```
# --seed--
@ -38,12 +46,12 @@ assert.strictEqual(euler444(), 1.200856722e263);
## --seed-contents--
```js
function euler444() {
function roundtableLottery() {
return true;
}
euler444();
roundtableLottery();
```
# --solutions--

View File

@ -8,20 +8,26 @@ dashedName: problem-445-retractions-a
# --description--
For every integer n>1, the family of functions fn,a,b is defined
For every integer $n > 1$, the family of functions $f_{n, a, b}$ is defined by:
by fn,a,b(x)≡ax+b mod n for a,b,x integer and 0
$f_{n, a, b}(x) ≡ ax + b\bmod n$ for $a, b, x$ integer and $0 \lt a \lt n$, $0 \le b \lt n$, $0 \le x \lt n$.
You are given that ∑ R(c) for c=C(100 000,k), and 1 ≤ k ≤99 999 ≡628701600 (mod 1 000 000 007). (C(n,k) is the binomial coefficient).
We will call $f_{n, a, b}$ a retraction if $f_{n, a, b}(f_{n, a, b}(x)) \equiv f_{n, a, b}(x)\bmod n$ for every $0 \le x \lt n$.
Find ∑ R(c) for c=C(10 000 000,k), and 1 ≤k≤ 9 999 999. Give your answer modulo 1 000 000 007.
Let $R(n)$ be the number of retractions for $n$.
You are given that
$$\sum_{k = 1}^{99\\,999} R(\displaystyle\binom{100\\,000}{k}) \equiv 628\\,701\\,600\bmod 1\\,000\\,000\\,007$$
Find $$\sum_{k = 1}^{9\\,999\\,999} R(\displaystyle\binom{10\\,000\\,000}{k})$$ Give your answer modulo $1\\,000\\,000\\,007$.
# --hints--
`euler445()` should return 659104042.
`retractionsA()` should return `659104042`.
```js
assert.strictEqual(euler445(), 659104042);
assert.strictEqual(retractionsA(), 659104042);
```
# --seed--
@ -29,12 +35,12 @@ assert.strictEqual(euler445(), 659104042);
## --seed-contents--
```js
function euler445() {
function retractionsA() {
return true;
}
euler445();
retractionsA();
```
# --solutions--

View File

@ -8,20 +8,26 @@ dashedName: problem-446-retractions-b
# --description--
For every integer n>1, the family of functions fn,a,b is defined
For every integer $n > 1$, the family of functions $f_{n, a, b}$ is defined by:
by fn,a,b(x)≡ax+b mod n for a,b,x integer and 0
$f_{n, a, b}(x) ≡ ax + b\bmod n$ for $a, b, x$ integer and $0 \lt a \lt n$, $0 \le b \lt n$, $0 \le x \lt n$.
F(N)=∑R(n4+4) for 1≤n≤N. F(1024)=77532377300600.
We will call $f_{n, a, b}$ a retraction if $f_{n, a, b}(f_{n, a, b}(x)) \equiv f_{n, a, b}(x)\bmod n$ for every $0 \le x \lt n$.
Find F(107) (mod 1 000 000 007)
Let $R(n)$ be the number of retractions for $n$.
$F(N) = \displaystyle\sum_{n = 1}^N R(n^4 + 4)$.
$F(1024) = 77\\,532\\,377\\,300\\,600$.
Find $F({10}^7)$. Give your answer modulo $1\\,000\\,000\\,007$.
# --hints--
`euler446()` should return 907803852.
`retractionsB()` should return `907803852`.
```js
assert.strictEqual(euler446(), 907803852);
assert.strictEqual(retractionsB(), 907803852);
```
# --seed--
@ -29,12 +35,12 @@ assert.strictEqual(euler446(), 907803852);
## --seed-contents--
```js
function euler446() {
function retractionsB() {
return true;
}
euler446();
retractionsB();
```
# --solutions--

View File

@ -8,20 +8,26 @@ dashedName: problem-447-retractions-c
# --description--
For every integer n>1, the family of functions fn,a,b is defined
For every integer $n > 1$, the family of functions $f_{n, a, b}$ is defined by:
by fn,a,b(x)≡ax+b mod n for a,b,x integer and 0
$f_{n, a, b}(x) ≡ ax + b\bmod n$ for $a, b, x$ integer and $0 \lt a \lt n$, $0 \le b \lt n$, $0 \le x \lt n$.
F(N)=∑R(n) for 2≤n≤N. F(107)≡638042271 (mod 1 000 000 007).
We will call $f_{n, a, b}$ a retraction if $f_{n, a, b}(f_{n, a, b}(x)) \equiv f_{n, a, b}(x)\bmod n$ for every $0 \le x \lt n$.
Find F(1014) (mod 1 000 000 007).
Let $R(n)$ be the number of retractions for $n$.
$F(N) = \displaystyle\sum_{n = 2}^N R(n)$.
$F({10}^7) ≡ 638\\,042\\,271\bmod 1\\,000\\,000\\,007$.
Find $F({10}^{14})$. Give your answer modulo $1\\,000\\,000\\,007$.
# --hints--
`euler447()` should return 530553372.
`retractionsC()` should return `530553372`.
```js
assert.strictEqual(euler447(), 530553372);
assert.strictEqual(retractionsC(), 530553372);
```
# --seed--
@ -29,12 +35,12 @@ assert.strictEqual(euler447(), 530553372);
## --seed-contents--
```js
function euler447() {
function retractionsC() {
return true;
}
euler447();
retractionsC();
```
# --solutions--

View File

@ -8,22 +8,24 @@ dashedName: problem-448-average-least-common-multiple
# --description--
The function lcm(a,b) denotes the least common multiple of a and b.
The function $lcm(a, b)$ denotes the least common multiple of $a$ and $b$.
Let A(n) be the average of the values of lcm(n,i) for 1≤i≤n.
Let $A(n)$ be the average of the values of $lcm(n, i)$ for $1 ≤ i ≤ n$.
E.g: A(2)=(2+2)/2=2 and A(10)=(10+10+30+20+10+30+70+40+90+10)/10=32.
E.g: $A(2) = \frac{2 + 2}{2} = 2$ and $A(10) = \frac{10 + 10 + 30 + 20 + 10 + 30 + 70 + 40 + 90 + 10}{10} = 32$.
Let S(n)=∑A(k) for 1≤k≤n. S(100)=122726.
Let $S(n) = \sum A(k)$ for $1 ≤ k ≤ n$.
Find S(99999999019) mod 999999017.
$S(100) = 122\\,726$.
Find $S(99\\,999\\,999\\,019)\bmod 999\\,999\\,017$.
# --hints--
`euler448()` should return 106467648.
`averageLCM()` should return `106467648`.
```js
assert.strictEqual(euler448(), 106467648);
assert.strictEqual(averageLCM(), 106467648);
```
# --seed--
@ -31,12 +33,12 @@ assert.strictEqual(euler448(), 106467648);
## --seed-contents--
```js
function euler448() {
function averageLCM() {
return true;
}
euler448();
averageLCM();
```
# --solutions--

View File

@ -8,24 +8,22 @@ dashedName: problem-449-chocolate-covered-candy
# --description--
Phil the confectioner is making a new batch of chocolate covered candy. Each candy centre is shaped like an ellipsoid of revolution defined by the equation: b2x2 + b2y2 + a2z2 = a2b2.
Phil the confectioner is making a new batch of chocolate covered candy. Each candy centre is shaped like an ellipsoid of revolution defined by the equation: $b^2x^2 + b^2y^2 + a^2z^2 = a^2b^2$.
Phil wants to know how much chocolate is needed to cover one candy centre with a uniform coat of chocolate one millimeter thick. If a=1 mm and b=1 mm, the amount of chocolate required is
Phil wants to know how much chocolate is needed to cover one candy centre with a uniform coat of chocolate one millimeter thick.
283 π mm3
If $a = 1$ mm and $b = 1$ mm, the amount of chocolate required is $\frac{28}{3} \pi$ mm<sup>3</sup>
<!-- TODO Use MathJax -->
If $a = 2$ mm and $b = 1$ mm, the amount of chocolate required is approximately 60.35475635 mm<sup>3</sup>.
If a=2 mm and b=1 mm, the amount of chocolate required is approximately 60.35475635 mm3.
Find the amount of chocolate in mm3 required if a=3 mm and b=1 mm. Give your answer as the number rounded to 8 decimal places behind the decimal point.
Find the amount of chocolate in mm<sup>3</sup> required if $a = 3$ mm and $b = 1$ mm. Give your answer as the number rounded to 8 decimal places behind the decimal point.
# --hints--
`euler449()` should return 103.37870096.
`chocolateCoveredCandy()` should return `103.37870096`.
```js
assert.strictEqual(euler449(), 103.37870096);
assert.strictEqual(chocolateCoveredCandy(), 103.37870096);
```
# --seed--
@ -33,12 +31,12 @@ assert.strictEqual(euler449(), 103.37870096);
## --seed-contents--
```js
function euler449() {
function chocolateCoveredCandy() {
return true;
}
euler449();
chocolateCoveredCandy();
```
# --solutions--

View File

@ -10,34 +10,40 @@ dashedName: problem-450-hypocycloid-and-lattice-points
A hypocycloid is the curve drawn by a point on a small circle rolling inside a larger circle. The parametric equations of a hypocycloid centered at the origin, and starting at the right most point is given by:
$x(t) = (R - r) \\cos(t) + r \\cos(\\frac {R - r} r t)$
$$x(t) = (R - r) \cos(t) + r \cos(\frac{R - r}{r}t)$$
$y(t) = (R - r) \\sin(t) - r \\sin(\\frac {R - r} r t)$
$$y(t) = (R - r) \sin(t) - r \sin(\frac{R - r}{r} t)$$
Where R is the radius of the large circle and r the radius of the small circle.
Where $R$ is the radius of the large circle and $r$ the radius of the small circle.
Let $C(R, r)$ be the set of distinct points with integer coordinates on the hypocycloid with radius R and r and for which there is a corresponding value of t such that $\\sin(t)$ and $\\cos(t)$ are rational numbers.
Let $C(R, r)$ be the set of distinct points with integer coordinates on the hypocycloid with radius $R$ and $r$ and for which there is a corresponding value of $t$ such that $\sin(t)$ and $\cos(t)$ are rational numbers.
Let $S(R, r) = \\sum\_{(x,y) \\in C(R, r)} |x| + |y|$ be the sum of the absolute values of the x and y coordinates of the points in $C(R, r)$.
Let $S(R, r) = \sum\_{(x,y) \in C(R, r)} |x| + |y|$ be the sum of the absolute values of the $x$ and $y$ coordinates of the points in $C(R, r)$.
Let $T(N) = \\sum*{R = 3}^N \\sum*{r=1}^{\\lfloor \\frac {R - 1} 2 \\rfloor} S(R, r)$ be the sum of $S(R, r)$ for R and r positive integers, $R\\leq N$ and $2r &lt; R$.
Let $T(N) = \sum_{R = 3}^N \sum_{r=1}^{\left\lfloor \frac{R - 1}{2} \right\rfloor} S(R, r)$ be the sum of $S(R, r)$ for $R$ and $r$ positive integers, $R\leq N$ and $2r &lt; R$.
You are given:C(3, 1) = {(3, 0), (-1, 2), (-1,0), (-1,-2)} C(2500, 1000) = {(2500, 0), (772, 2376), (772, -2376), (516, 1792), (516, -1792), (500, 0), (68, 504), (68, -504),(-1356, 1088), (-1356, -1088), (-1500, 1000), (-1500, -1000)}
You are given:
Note: (-625, 0) is not an element of C(2500, 1000) because $\\sin(t)$ is not a rational number for the corresponding values of t.
$$\begin{align}
C(3, 1) = & \\{(3, 0), (-1, 2), (-1,0), (-1,-2)\\} \\\\
C(2500, 1000) = & \\{(2500, 0), (772, 2376), (772, -2376), (516, 1792), (516, -1792), (500, 0), (68, 504), \\\\
&(68, -504),(-1356, 1088), (-1356, -1088), (-1500, 1000), (-1500, -1000)\\}
\end{align}$$
S(3, 1) = (|3| + |0|) + (|-1| + |2|) + (|-1| + |0|) + (|-1| + |-2|) = 10
**Note:** (-625, 0) is not an element of $C(2500, 1000)$ because $\sin(t)$ is not a rational number for the corresponding values of t.
T(3) = 10; T(10) = 524 ;T(100) = 580442; T(103) = 583108600.
$S(3, 1) = (|3| + |0|) + (|-1| + |2|) + (|-1| + |0|) + (|-1| + |-2|) = 10$
Find T(106).
$T(3) = 10$; $T(10) = 524$; $T(100) = 580\\,442$; $T({10}^3) = 583\\,108\\,600$.
Find $T({10}^6)$.
# --hints--
`euler450()` should return 583333163984220900.
`hypocycloidAndLatticePoints()` should return `583333163984220900`.
```js
assert.strictEqual(euler450(), 583333163984220900);
assert.strictEqual(hypocycloidAndLatticePoints(), 583333163984220900);
```
# --seed--
@ -45,12 +51,12 @@ assert.strictEqual(euler450(), 583333163984220900);
## --seed-contents--
```js
function euler450() {
function hypocycloidAndLatticePoints() {
return true;
}
euler450();
hypocycloidAndLatticePoints();
```
# --solutions--

View File

@ -12,32 +12,31 @@ Consider the number 15.
There are eight positive numbers less than 15 which are coprime to 15: 1, 2, 4, 7, 8, 11, 13, 14.
The modular inverses of these numbers modulo 15 are: 1, 8, 4, 13, 2, 11, 7, 14
The modular inverses of these numbers modulo 15 are: 1, 8, 4, 13, 2, 11, 7, 14 because
because
$$\begin{align}
& 1 \times 1\bmod 15 = 1 \\\\
& 2 \times 8 = 16\bmod 15 = 1 \\\\
& 4 \times 4 = 16\bmod 15 = 1 \\\\
& 7 \times 13 = 91\bmod 15 = 1 \\\\
& 11 \times 11 = 121\bmod 15 = 1 \\\\
& 14 \times 14 = 196\bmod 15 = 1
\end{align}$$
1\*1 mod 15=1
Let $I(n)$ be the largest positive number $m$ smaller than $n - 1$ such that the modular inverse of $m$ modulo $n$ equals $m$ itself.
2\*8=16 mod 15=1
So $I(15) = 11$.
4\*4=16 mod 15=1
Also $I(100) = 51$ and $I(7) = 1$.
7\*13=91 mod 15=1
11\*11=121 mod 15=1
14\*14=196 mod 15=1
Let I(n) be the largest positive number m smaller than n-1 such that the modular inverse of m modulo n equals m itself. So I(15)=11. Also I(100)=51 and I(7)=1.
Find ∑I(n) for 3≤n≤2·107
Find $\sum I(n)$ for $3 ≤ n ≤ 2 \times {10}^7$
# --hints--
`euler451()` should return 153651073760956.
`modularInverses()` should return `153651073760956`.
```js
assert.strictEqual(euler451(), 153651073760956);
assert.strictEqual(modularInverses(), 153651073760956);
```
# --seed--
@ -45,12 +44,12 @@ assert.strictEqual(euler451(), 153651073760956);
## --seed-contents--
```js
function euler451() {
function modularInverses() {
return true;
}
euler451();
modularInverses();
```
# --solutions--

View File

@ -8,20 +8,20 @@ dashedName: problem-452-long-products
# --description--
Define F(m,n) as the number of n-tuples of positive integers for which the product of the elements doesn't exceed m.
Define $F(m, n)$ as the number of $n$-tuples of positive integers for which the product of the elements doesn't exceed $m$.
F(10, 10) = 571.
$F(10, 10) = 571$.
F(106, 106) mod 1 234 567 891 = 252903833.
$F({10}^6, {10}^6)\bmod 1\\,234\\,567\\,891 = 252\\,903\\,833$.
Find F(109, 109) mod 1 234 567 891.
Find $F({10}^9, {10}^9)\bmod 1\\,234\\,567\\,891$.
# --hints--
`euler452()` should return 345558983.
`longProducts()` should return `345558983`.
```js
assert.strictEqual(euler452(), 345558983);
assert.strictEqual(longProducts(), 345558983);
```
# --seed--
@ -29,12 +29,12 @@ assert.strictEqual(euler452(), 345558983);
## --seed-contents--
```js
function euler452() {
function longProducts() {
return true;
}
euler452();
longProducts();
```
# --solutions--

View File

@ -10,20 +10,22 @@ dashedName: problem-453-lattice-quadrilaterals
A simple quadrilateral is a polygon that has four distinct vertices, has no straight angles and does not self-intersect.
Let Q(m, n) be the number of simple quadrilaterals whose vertices are lattice points with coordinates (x,y) satisfying 0 ≤ x ≤ m and 0 ≤ y ≤ n.
Let $Q(m, n)$ be the number of simple quadrilaterals whose vertices are lattice points with coordinates ($x$, $y$) satisfying $0 ≤ x ≤ m$ and $0 ≤ y ≤ n$.
For example, Q(2, 2) = 94 as can be seen below:
For example, $Q(2, 2) = 94$ as can be seen below:
It can also be verified that Q(3, 7) = 39590, Q(12, 3) = 309000 and Q(123, 45) = 70542215894646.
<img class="img-responsive center-block" alt="94 quadrilaterals whose vertices are lattice points with coordinates (x, y) satiffying 0 &le; x &le; m and 0 &le; y &le; n" src="https://cdn.freecodecamp.org/curriculum/project-euler/lattice-quadrilaterals.png" style="background-color: white; padding: 10px;">
Find Q(12345, 6789) mod 135707531.
It can also be verified that $Q(3, 7) = 39\\,590$, $Q(12, 3) = 309\\,000$ and $Q(123, 45) = 70\\,542\\,215\\,894\\,646$.
Find $Q(12\\,345, 6\\,789)\bmod 135\\,707\\,531$.
# --hints--
`euler453()` should return 104354107.
`latticeQuadrilaterals()` should return `104354107`.
```js
assert.strictEqual(euler453(), 104354107);
assert.strictEqual(latticeQuadrilaterals(), 104354107);
```
# --seed--
@ -31,12 +33,12 @@ assert.strictEqual(euler453(), 104354107);
## --seed-contents--
```js
function euler453() {
function latticeQuadrilaterals() {
return true;
}
euler453();
latticeQuadrilaterals();
```
# --solutions--

View File

@ -8,20 +8,22 @@ dashedName: problem-454-diophantine-reciprocals-iii
# --description--
In the following equation x, y, and n are positive integers. 1/x + 1/y= 1/n
In the following equation $x$, $y$, and $n$ are positive integers.
<!-- TODO Use MathJax -->
$$\frac{1}{x} + \frac{1}{y} = \frac{1}{n}$$
For a limit L we define F(L) as the number of solutions which satisfy x &lt; y ≤ L.
For a limit $L$ we define $F(L)$ as the number of solutions which satisfy $x &lt; y ≤ L$.
We can verify that F(15) = 4 and F(1000) = 1069. Find F(1012).
We can verify that $F(15) = 4$ and $F(1000) = 1069$.
Find $F({10}^{12})$.
# --hints--
`euler454()` should return 5435004633092.
`diophantineReciprocalsThree()` should return `5435004633092`.
```js
assert.strictEqual(euler454(), 5435004633092);
assert.strictEqual(diophantineReciprocalsThree(), 5435004633092);
```
# --seed--
@ -29,12 +31,12 @@ assert.strictEqual(euler454(), 5435004633092);
## --seed-contents--
```js
function euler454() {
function diophantineReciprocalsThree() {
return true;
}
euler454();
diophantineReciprocalsThree();
```
# --solutions--

View File

@ -8,18 +8,25 @@ dashedName: problem-455-powers-with-trailing-digits
# --description--
Let f(n) be the largest positive integer x less than 109 such that the last 9 digits of nx form the number x (including leading zeros), or zero if no such integer exists.
Let $f(n)$ be the largest positive integer $x$ less than ${10}^9$ such that the last 9 digits of $n^x$ form the number $x$ (including leading zeros), or zero if no such integer exists.
For example:
f(4) = 411728896 (4411728896 = ...490411728896) f(10) = 0 f(157) = 743757 (157743757 = ...567000743757) Σf(n), 2 ≤ n ≤ 103 = 442530011399 Find Σf(n), 2 ≤ n ≤ 106.
$$\begin{align}
& f(4) = 411\\,728\\,896 (4^{411\\,728\\,896} = ...490\underline{411728896}) \\\\
& f(10) = 0 \\\\
& f(157) = 743\\,757 (157^{743\\,757} = ...567\underline{000743757}) \\\\
& Σf(n), 2 ≤ n ≤ 103 = 442\\,530\\,011\\,399
\end{align}$$
Find $\sum f(n)$, $2 ≤ n ≤ {10}^6$.
# --hints--
`euler455()` should return 450186511399999.
`powersWithTrailingDigits()` should return `450186511399999`.
```js
assert.strictEqual(euler455(), 450186511399999);
assert.strictEqual(powersWithTrailingDigits(), 450186511399999);
```
# --seed--
@ -27,12 +34,12 @@ assert.strictEqual(euler455(), 450186511399999);
## --seed-contents--
```js
function euler455() {
function powersWithTrailingDigits() {
return true;
}
euler455();
powersWithTrailingDigits();
```
# --solutions--

View File

@ -8,24 +8,35 @@ dashedName: problem-456-triangles-containing-the-origin-ii
# --description--
Define:xn = (1248n mod 32323) - 16161yn = (8421n mod 30103) - 15051
Define:
Pn = {(x1, y1), (x2, y2), ..., (xn, yn)}
$$\begin{align}
& x_n = ({1248}^n\bmod 32323) - 16161 \\\\
& y_n = ({8421}^n\bmod 30103) - 15051 \\\\
& P_n = \\{(x_1, y_1), (x_2, y_2), \ldots, (x_n, y_n)\\}
\end{align}$$
For example, P8 = {(-14913, -6630), (-10161, 5625), (5226, 11896), (8340, -10778), (15852, -5203), (-15165, 11295), (-1427, -14495), (12407, 1060)}.
For example,
$$P_8 = \\{(-14913, -6630), (-10161, 5625), (5226, 11896), (8340, -10778), (15852, -5203), (-15165, 11295), (-1427, -14495), (12407, 1060)\\}$$
Let C(n) be the number of triangles whose vertices are in Pn which contain the origin in the interior.
Let $C(n)$ be the number of triangles whose vertices are in $P_n$ which contain the origin in the interior.
Examples: C(8) = 20 C(600) = 8950634 C(40 000) = 2666610948988
Examples:
Find C(2 000 000).
$$\begin{align}
& C(8) = 20 \\\\
& C(600) = 8\\,950\\,634 \\\\
& C(40\\,000) = 2\\,666\\,610\\,948\\,988
\end{align}$$
Find $C(2\\,000\\,000)$.
# --hints--
`euler456()` should return 333333208685971500.
`trianglesContainingOriginTwo()` should return `333333208685971500`.
```js
assert.strictEqual(euler456(), 333333208685971500);
assert.strictEqual(trianglesContainingOriginTwo(), 333333208685971500);
```
# --seed--
@ -33,12 +44,12 @@ assert.strictEqual(euler456(), 333333208685971500);
## --seed-contents--
```js
function euler456() {
function trianglesContainingOriginTwo() {
return true;
}
euler456();
trianglesContainingOriginTwo();
```
# --solutions--

View File

@ -8,22 +8,22 @@ dashedName: problem-457-a-polynomial-modulo-the-square-of-a-prime
# --description--
Let f(n) = n2 - 3n - 1.
Let $f(n) = n^2 - 3n - 1$.
Let p be a prime.
Let $p$ be a prime.
Let R(p) be the smallest positive integer n such that f(n) mod p2 = 0 if such an integer n exists, otherwise R(p) = 0.
Let $R(p)$ be the smallest positive integer $n$ such that $f(n)\bmod p^2 = 0$ if such an integer $n$ exists, otherwise $R(p) = 0$.
Let SR(L) be R(p) for all primes not exceeding L.
Let $SR(L)$ be $\sum R(p)$ for all primes not exceeding $L$.
Find SR(107).
Find $SR({10}^7)$.
# --hints--
`euler457()` should return 2647787126797397000.
`polynomialModuloSquareOfPrime()` should return `2647787126797397000`.
```js
assert.strictEqual(euler457(), 2647787126797397000);
assert.strictEqual(polynomialModuloSquareOfPrime(), 2647787126797397000);
```
# --seed--
@ -31,12 +31,12 @@ assert.strictEqual(euler457(), 2647787126797397000);
## --seed-contents--
```js
function euler457() {
function polynomialModuloSquareOfPrime() {
return true;
}
euler457();
polynomialModuloSquareOfPrime();
```
# --solutions--

View File

@ -8,20 +8,20 @@ dashedName: problem-458-permutations-of-project
# --description--
Consider the alphabet A made out of the letters of the word "project": A={c,e,j,o,p,r,t}.
Consider the alphabet $A$ made out of the letters of the word `project`: $A = \\{c, e, j, o, p, r, t\\}$.
Let T(n) be the number of strings of length n consisting of letters from A that do not have a substring that is one of the 5040 permutations of "project".
Let $T(n)$ be the number of strings of length $n$ consisting of letters from $A$ that do not have a substring that is one of the 5040 permutations of `project`.
T(7)=77-7!=818503.
$T(7) = 7^7 - 7! = 818\\,503$.
Find T(1012). Give the last 9 digits of your answer.
Find $T({10}^{12})$. Give the last 9 digits of your answer.
# --hints--
`euler458()` should return 423341841.
`permutationsOfProject()` should return `423341841`.
```js
assert.strictEqual(euler458(), 423341841);
assert.strictEqual(permutationsOfProject(), 423341841);
```
# --seed--
@ -29,12 +29,12 @@ assert.strictEqual(euler458(), 423341841);
## --seed-contents--
```js
function euler458() {
function permutationsOfProject() {
return true;
}
euler458();
permutationsOfProject();
```
# --solutions--

View File

@ -8,28 +8,38 @@ dashedName: problem-459-flipping-game
# --description--
The flipping game is a two player game played on a N by N square board.
The flipping game is a two player game played on a $N$ by $N$ square board.
Each square contains a disk with one side white and one side black.
The game starts with all disks showing their white side.
A turn consists of flipping all disks in a rectangle with the following properties: the upper right corner of the rectangle contains a white disk the rectangle width is a perfect square (1, 4, 9, 16, ...) the rectangle height is a triangular number (1, 3, 6, 10, ...)
A turn consists of flipping all disks in a rectangle with the following properties:
- the upper right corner of the rectangle contains a white disk
- the rectangle width is a perfect square (1, 4, 9, 16, ...)
- the rectangle height is a triangular number (1, 3, 6, 10, ...)
<img class="img-responsive center-block" alt="flipping all disks in a 4x3 rectangle on a 5x5 board" src="https://cdn.freecodecamp.org/curriculum/project-euler/flipping-game-1.png" style="background-color: white; padding: 10px;">
Players alternate turns. A player wins by turning the grid all black.
Let W(N) be the number of winning moves for the first player on a N by N board with all disks white, assuming perfect play. W(1) = 1, W(2) = 0, W(5) = 8 and W(102) = 31395.
Let $W(N)$ be the number of winning moves for the first player on a $N$ by $N$ board with all disks white, assuming perfect play.
For N=5, the first player's eight winning first moves are:
$W(1) = 1$, $W(2) = 0$, $W(5) = 8$ and $W({10}^2) = 31\\,395$.
Find W(106).
For $N = 5$, the first player's eight winning first moves are:
<img class="img-responsive center-block" alt="eight winning first moves for N = 5" src="https://cdn.freecodecamp.org/curriculum/project-euler/flipping-game-2.png" style="background-color: white; padding: 10px;">
Find $W({10}^6)$.
# --hints--
`euler459()` should return 3996390106631.
`flippingGame()` should return `3996390106631`.
```js
assert.strictEqual(euler459(), 3996390106631);
assert.strictEqual(flippingGame(), 3996390106631);
```
# --seed--
@ -37,12 +47,12 @@ assert.strictEqual(euler459(), 3996390106631);
## --seed-contents--
```js
function euler459() {
function flippingGame() {
return true;
}
euler459();
flippingGame();
```
# --solutions--

View File

@ -8,24 +8,33 @@ dashedName: problem-460-an-ant-on-the-move
# --description--
On the Euclidean plane, an ant travels from point A(0, 1) to point B(d, 1) for an integer d.
On the Euclidean plane, an ant travels from point $A(0, 1)$ to point $B(d, 1)$ for an integer $d$.
In each step, the ant at point (x0, y0) chooses one of the lattice points (x1, y1) which satisfy x1 ≥ 0 and y1 ≥ 1 and goes straight to (x1, y1) at a constant velocity v. The value of v depends on y0 and y1 as follows: If y0 = y1, the value of v equals y0. If y0 ≠ y1, the value of v equals (y1 - y0) / (ln(y1) - ln(y0)).
In each step, the ant at point ($x_0$, $y_0$) chooses one of the lattice points ($x_1$, $y_1$) which satisfy $x_1 ≥ 0$ and $y_1 ≥ 1$ and goes straight to ($x_1$, $y_1$) at a constant velocity $v$. The value of $v$ depends on $y_0$ and $y_1$ as follows:
The left image is one of the possible paths for d = 4. First the ant goes from A(0, 1) to P1(1, 3) at velocity (3 - 1) / (ln(3) - ln(1)) ≈ 1.8205. Then the required time is sqrt(5) / 1.8205 ≈ 1.2283. From P1(1, 3) to P2(3, 3) the ant travels at velocity 3 so the required time is 2 / 3 ≈ 0.6667. From P2(3, 3) to B(4, 1) the ant travels at velocity (1 - 3) / (ln(1) - ln(3)) ≈ 1.8205 so the required time is sqrt(5) / 1.8205 ≈ 1.2283. Thus the total required time is 1.2283 + 0.6667 + 1.2283 = 3.1233.
- If $y_0 = y_1$, the value of $v$ equals $y_0$.
- If $y_0 ≠ y_1$, the value of $v$ equals $\frac{y_1 - y_0}{\ln y_1 - \ln y_0}$.
The right image is another path. The total required time is calculated as 0.98026 + 1 + 0.98026 = 2.96052. It can be shown that this is the quickest path for d = 4.
The left image is one of the possible paths for $d = 4$. First the ant goes from $A(0, 1)$ to $P_1(1, 3)$ at velocity $\frac{3 - 1}{\ln 3 - \ln 1} ≈ 1.8205$. Then the required time is $\frac{\sqrt{5}}{1.820} ≈ 1.2283$.
Let F(d) be the total required time if the ant chooses the quickest path. For example, F(4) ≈ 2.960516287. We can verify that F(10) ≈ 4.668187834 and F(100)9.217221972.
From $P_1(1, 3)$ to $P_2(3, 3)$ the ant travels at velocity 3 so the required time is $\frac{2}{3} ≈ 0.6667$. From $P_2(3, 3)$ to $B(4, 1)$ the ant travels at velocity $\frac{1 - 3}{\ln 1 - \ln 3} ≈ 1.8205$ so the required time is $\frac{\sqrt{5}}{1.8205}1.2283$.
Find F(10000). Give your answer rounded to nine decimal places.
Thus the total required time is $1.2283 + 0.6667 + 1.2283 = 3.1233$.
The right image is another path. The total required time is calculated as $0.98026 + 1 + 0.98026 = 2.96052$. It can be shown that this is the quickest path for $d = 4$.
<img class="img-responsive center-block" alt="two possible paths for d = 4" src="https://cdn.freecodecamp.org/curriculum/project-euler/an-ant-on-the-move.jpg" style="background-color: white; padding: 10px;">
Let $F(d)$ be the total required time if the ant chooses the quickest path. For example, $F(4) ≈ 2.960\\,516\\,287$. We can verify that $F(10) ≈ 4.668\\,187\\,834$ and $F(100) ≈ 9.217\\,221\\,972$.
Find $F(10\\,000)$. Give your answer rounded to nine decimal places.
# --hints--
`euler460()` should return 18.420738199.
`antOnTheMove()` should return `18.420738199`.
```js
assert.strictEqual(euler460(), 18.420738199);
assert.strictEqual(antOnTheMove(), 18.420738199);
```
# --seed--
@ -33,12 +42,12 @@ assert.strictEqual(euler460(), 18.420738199);
## --seed-contents--
```js
function euler460() {
function antOnTheMove() {
return true;
}
euler460();
antOnTheMove();
```
# --solutions--