fix(curriculum): clean-up Project Euler 301-320 (#42926)
* fix: clean-up Project Euler 301-320 * 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:
@ -12,25 +12,30 @@ Nim is a game played with heaps of stones, where two players take it in turn to
|
||||
|
||||
We'll consider the three-heap normal-play version of Nim, which works as follows:
|
||||
|
||||
- At the start of the game there are three heaps of stones.
|
||||
- On his turn the player removes any positive number of stones from any single heap.
|
||||
- The first player unable to move (because no stones remain) loses.
|
||||
- At the start of the game there are three heaps of stones.
|
||||
- On his turn the player removes any positive number of stones from any single heap.
|
||||
- The first player unable to move (because no stones remain) loses.
|
||||
|
||||
If (n1,n2,n3) indicates a Nim position consisting of heaps of size n1, n2 and n3 then there is a simple function X(n1,n2,n3) — that you may look up or attempt to deduce for yourself — that returns: zero if, with perfect strategy, the player about to move will eventually lose; or non-zero if, with perfect strategy, the player about to move will eventually win. For example X(1,2,3) = 0 because, no matter what the current player does, his opponent can respond with a move that leaves two heaps of equal size, at which point every move by the current player can be mirrored by his opponent until no stones remain; so the current player loses. To illustrate:
|
||||
If ($n_1$, $n_2$, $n_3$) indicates a Nim position consisting of heaps of size $n_1$, $n_2$ and $n_3$ then there is a simple function $X(n_1,n_2,n_3)$ — that you may look up or attempt to deduce for yourself — that returns:
|
||||
|
||||
- current player moves to (1,2,1)
|
||||
- opponent moves to (1,0,1)
|
||||
- current player moves to (0,0,1)
|
||||
- opponent moves to (0,0,0), and so wins.
|
||||
- zero if, with perfect strategy, the player about to move will eventually lose; or
|
||||
- non-zero if, with perfect strategy, the player about to move will eventually win.
|
||||
|
||||
For how many positive integers n ≤ 230 does X(n,2n,3n) = 0 ?
|
||||
For example $X(1, 2, 3) = 0$ because, no matter what the current player does, his opponent can respond with a move that leaves two heaps of equal size, at which point every move by the current player can be mirrored by his opponent until no stones remain; so the current player loses. To illustrate:
|
||||
|
||||
- current player moves to (1,2,1)
|
||||
- opponent moves to (1,0,1)
|
||||
- current player moves to (0,0,1)
|
||||
- opponent moves to (0,0,0), and so wins.
|
||||
|
||||
For how many positive integers $n ≤ 2^{30}$ does $X(n, 2n, 3n) = 0$?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler301()` should return 2178309.
|
||||
`nim()` should return `2178309`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler301(), 2178309);
|
||||
assert.strictEqual(nim(), 2178309);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -38,12 +43,12 @@ assert.strictEqual(euler301(), 2178309);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler301() {
|
||||
function nim() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler301();
|
||||
nim();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,26 +8,26 @@ dashedName: problem-302-strong-achilles-numbers
|
||||
|
||||
# --description--
|
||||
|
||||
A positive integer n is powerful if p2 is a divisor of n for every prime factor p in n.
|
||||
A positive integer $n$ is powerful if $p^2$ is a divisor of $n$ for every prime factor $p$ in $n$.
|
||||
|
||||
A positive integer n is a perfect power if n can be expressed as a power of another positive integer.
|
||||
A positive integer $n$ is a perfect power if $n$ can be expressed as a power of another positive integer.
|
||||
|
||||
A positive integer n is an Achilles number if n is powerful but not a perfect power. For example, 864 and 1800 are Achilles numbers: 864 = 25·33 and 1800 = 23·32·52.
|
||||
A positive integer $n$ is an Achilles number if $n$ is powerful but not a perfect power. For example, 864 and 1800 are Achilles numbers: $864 = 2^5 \times 3^3$ and $1800 = 2^3 \times 3^2 \times 5^2$.
|
||||
|
||||
We shall call a positive integer S a Strong Achilles number if both S and φ(S) are Achilles numbers.1 For example, 864 is a Strong Achilles number: φ(864) = 288 = 25·32. However, 1800 isn't a Strong Achilles number because: φ(1800) = 480 = 25·31·51.
|
||||
We shall call a positive integer $S$ a Strong Achilles number if both $S$ and $φ(S)$ are Achilles numbers. $φ$ denotes Euler's totient function.
|
||||
|
||||
There are 7 Strong Achilles numbers below 104 and 656 below 108.
|
||||
For example, 864 is a Strong Achilles number: $φ(864) = 288 = 2^5 \times 3^2$. However, 1800 isn't a Strong Achilles number because: $φ(1800) = 480 = 2^5 \times 3^1 \times 5^1$.
|
||||
|
||||
How many Strong Achilles numbers are there below 1018?
|
||||
There are 7 Strong Achilles numbers below ${10}^4$ and 656 below ${10}^8$.
|
||||
|
||||
1 φ denotes Euler's totient function.
|
||||
How many Strong Achilles numbers are there below ${10}^{18}$?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler302()` should return 1170060.
|
||||
`strongAchillesNumbers()` should return `1170060`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler302(), 1170060);
|
||||
assert.strictEqual(strongAchillesNumbers(), 1170060);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -35,12 +35,12 @@ assert.strictEqual(euler302(), 1170060);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler302() {
|
||||
function strongAchillesNumbers() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler302();
|
||||
strongAchillesNumbers();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,20 +8,20 @@ dashedName: problem-303-multiples-with-small-digits
|
||||
|
||||
# --description--
|
||||
|
||||
For a positive integer n, define f(n) as the least positive multiple of n that, written in base 10, uses only digits ≤ 2.
|
||||
For a positive integer $n$, define $f(n)$ as the least positive multiple of $n$ that, written in base 10, uses only digits $≤ 2$.
|
||||
|
||||
Thus f(2)=2, f(3)=12, f(7)=21, f(42)=210, f(89)=1121222.
|
||||
Thus $f(2) = 2$, $f(3) = 12$, $f(7) = 21$, $f(42) = 210$, $f(89) = 1\\,121\\,222$.
|
||||
|
||||
Also, .
|
||||
Also, $\displaystyle\sum_{n = 1}^{100} \frac{f(n)}{n} = 11\\,363\\,107$.
|
||||
|
||||
Find .
|
||||
Find $\displaystyle\sum_{n = 1}^{10\\,000} \frac{f(n)}{n}$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler303()` should return 1111981904675169.
|
||||
`multiplesWithSmallDigits()` should return `1111981904675169`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler303(), 1111981904675169);
|
||||
assert.strictEqual(multiplesWithSmallDigits(), 1111981904675169);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -29,12 +29,12 @@ assert.strictEqual(euler303(), 1111981904675169);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler303() {
|
||||
function multiplesWithSmallDigits() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler303();
|
||||
multiplesWithSmallDigits();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,22 +8,22 @@ dashedName: problem-304-primonacci
|
||||
|
||||
# --description--
|
||||
|
||||
For any positive integer n the function next_prime(n) returns the smallest prime p such that p>n.
|
||||
For any positive integer $n$ the function $\text{next_prime}(n)$ returns the smallest prime $p$ such that $p > n$.
|
||||
|
||||
The sequence a(n) is defined by: a(1)=next_prime(1014) and a(n)=next_prime(a(n-1)) for n>1.
|
||||
The sequence $a(n)$ is defined by: $a(1) = \text{next_prime}({10}^{14})$ and $a(n) = \text{next_prime}(a(n - 1))$ for $n > 1$.
|
||||
|
||||
The fibonacci sequence f(n) is defined by: f(0)=0, f(1)=1 and f(n)=f(n-1)+f(n-2) for n>1.
|
||||
The fibonacci sequence $f(n)$ is defined by: $f(0) = 0$, $f(1) = 1$ and $f(n) = f(n - 1) + f(n - 2)$ for $n > 1$.
|
||||
|
||||
The sequence b(n) is defined as f(a(n)).
|
||||
The sequence $b(n)$ is defined as $f(a(n))$.
|
||||
|
||||
Find ∑b(n) for 1≤n≤100 000. Give your answer mod 1234567891011.
|
||||
Find $\sum b(n)$ for $1≤n≤100\\,000$. Give your answer $\bmod 1\\,234\\,567\\,891\\,011$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler304()` should return 283988410192.
|
||||
`primonacci()` should return `283988410192`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler304(), 283988410192);
|
||||
assert.strictEqual(primonacci(), 283988410192);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -31,12 +31,12 @@ assert.strictEqual(euler304(), 283988410192);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler304() {
|
||||
function primonacci() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler304();
|
||||
primonacci();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,22 +8,22 @@ dashedName: problem-305-reflexive-position
|
||||
|
||||
# --description--
|
||||
|
||||
Let's call S the (infinite) string that is made by concatenating the consecutive positive integers (starting from 1) written down in base 10.
|
||||
Let's call $S$ the (infinite) string that is made by concatenating the consecutive positive integers (starting from 1) written down in base 10.
|
||||
|
||||
Thus, S = 1234567891011121314151617181920212223242...
|
||||
Thus, $S = 1234567891011121314151617181920212223242\ldots$
|
||||
|
||||
It's easy to see that any number will show up an infinite number of times in S.
|
||||
It's easy to see that any number will show up an infinite number of times in $S$.
|
||||
|
||||
Let's call f(n) the starting position of the nth occurrence of n in S. For example, f(1)=1, f(5)=81, f(12)=271 and f(7780)=111111365.
|
||||
Let's call $f(n)$ the starting position of the $n^{\text{th}}$ occurrence of $n$ in $S$. For example, $f(1) = 1$, $f(5) = 81$, $f(12) = 271$ and $f(7780) = 111\\,111\\,365$.
|
||||
|
||||
Find ∑f(3k) for 1≤k≤13.
|
||||
Find $\sum f(3^k) for 1 ≤ k ≤ 13$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler305()` should return 18174995535140.
|
||||
`reflexivePosition()` should return `18174995535140`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler305(), 18174995535140);
|
||||
assert.strictEqual(reflexivePosition(), 18174995535140);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -31,12 +31,12 @@ assert.strictEqual(euler305(), 18174995535140);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler305() {
|
||||
function reflexivePosition() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler305();
|
||||
reflexivePosition();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,20 +10,28 @@ dashedName: problem-306-paper-strip-game
|
||||
|
||||
The following game is a classic example of Combinatorial Game Theory:
|
||||
|
||||
Two players start with a strip of n white squares and they take alternate turns. On each turn, a player picks two contiguous white squares and paints them black. The first player who cannot make a move loses.
|
||||
Two players start with a strip of $n$ white squares and they take alternate turns. On each turn, a player picks two contiguous white squares and paints them black. The first player who cannot make a move loses.
|
||||
|
||||
If n = 1, there are no valid moves, so the first player loses automatically. If n = 2, there is only one valid move, after which the second player loses. If n = 3, there are two valid moves, but both leave a situation where the second player loses. If n = 4, there are three valid moves for the first player; she can win the game by painting the two middle squares. If n = 5, there are four valid moves for the first player (shown below in red); but no matter what she does, the second player (blue) wins.
|
||||
- $n = 1$: No valid moves, so the first player loses automatically.
|
||||
- $n = 2$: Only one valid move, after which the second player loses.
|
||||
- $n = 3$: Two valid moves, but both leave a situation where the second player loses.
|
||||
- $n = 4$: There are three valid moves for the first player; who is able to win the game by painting the two middle squares.
|
||||
- $n = 5$: Four valid moves for the first player (shown below in red); but no matter what the player does, the second player (blue) wins.
|
||||
|
||||
So, for 1 ≤ n ≤ 5, there are 3 values of n for which the first player can force a win. Similarly, for 1 ≤ n ≤ 50, there are 40 values of n for which the first player can force a win.
|
||||
<img class="img-responsive center-block" alt="valid starting moves for strip with 5 squares" src="https://cdn.freecodecamp.org/curriculum/project-euler/paper-strip-game.gif" style="background-color: white; padding: 10px;">
|
||||
|
||||
For 1 ≤ n ≤ 1 000 000, how many values of n are there for which the first player can force a win?
|
||||
So, for $1 ≤ n ≤ 5$, there are 3 values of $n$ for which the first player can force a win.
|
||||
|
||||
Similarly, for $1 ≤ n ≤ 50$, there are 40 values of $n$ for which the first player can force a win.
|
||||
|
||||
For $1 ≤ n ≤ 1\\,000\\,000$, how many values of $n$ are there for which the first player can force a win?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler306()` should return 852938.
|
||||
`paperStripGame()` should return `852938`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler306(), 852938);
|
||||
assert.strictEqual(paperStripGame(), 852938);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -31,12 +39,12 @@ assert.strictEqual(euler306(), 852938);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler306() {
|
||||
function paperStripGame() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler306();
|
||||
paperStripGame();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,18 +8,18 @@ dashedName: problem-307-chip-defects
|
||||
|
||||
# --description--
|
||||
|
||||
k defects are randomly distributed amongst n integrated-circuit chips produced by a factory (any number of defects may be found on a chip and each defect is independent of the other defects).
|
||||
$k$ defects are randomly distributed amongst $n$ integrated-circuit chips produced by a factory (any number of defects may be found on a chip and each defect is independent of the other defects).
|
||||
|
||||
Let p(k,n) represent the probability that there is a chip with at least 3 defects. For instance p(3,7) ≈ 0.0204081633.
|
||||
Let $p(k,n)$ represent the probability that there is a chip with at least 3 defects. For instance $p(3,7) ≈ 0.0204081633$.
|
||||
|
||||
Find p(20 000, 1 000 000) and give your answer rounded to 10 decimal places in the form 0.abcdefghij
|
||||
Find $p(20\\,000, 1\\,000\\,000)$ and give your answer rounded to 10 decimal places in the form 0.abcdefghij
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler307()` should return 0.7311720251.
|
||||
`chipDefects()` should return `0.7311720251`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler307(), 0.7311720251);
|
||||
assert.strictEqual(chipDefects(), 0.7311720251);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -27,12 +27,12 @@ assert.strictEqual(euler307(), 0.7311720251);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler307() {
|
||||
function chipDefects() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler307();
|
||||
chipDefects();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -12,18 +12,26 @@ A program written in the programming language Fractran consists of a list of fra
|
||||
|
||||
The internal state of the Fractran Virtual Machine is a positive integer, which is initially set to a seed value. Each iteration of a Fractran program multiplies the state integer by the first fraction in the list which will leave it an integer.
|
||||
|
||||
For example, one of the Fractran programs that John Horton Conway wrote for prime-generation consists of the following 14 fractions:1791 , 7885 , 1951 , 2338 , 2933 , 7729 , 9523 , 7719 , 117 , 1113 , 1311 , 152 , 17 , 551 . Starting with the seed integer 2, successive iterations of the program produce the sequence: 15, 825, 725, 1925, 2275, 425, ..., 68, 4, 30, ..., 136, 8, 60, ..., 544, 32, 240, ...
|
||||
For example, one of the Fractran programs that John Horton Conway wrote for prime-generation consists of the following 14 fractions:
|
||||
|
||||
The powers of 2 that appear in this sequence are 22, 23, 25, ... It can be shown that all the powers of 2 in this sequence have prime exponents and that all the primes appear as exponents of powers of 2, in proper order!
|
||||
$$\frac{17}{91}, \frac{78}{85}, \frac{19}{51}, \frac{23}{38}, \frac{29}{33}, \frac{77}{29}, \frac{95}{23}, \frac{77}{19}, \frac{1}{17}, \frac{11}{13}, \frac{13}{11}, \frac{15}{2}, \frac{1}{7}, \frac{55}{1}$$
|
||||
|
||||
If someone uses the above Fractran program to solve Project Euler Problem 7 (find the 10001st prime), how many iterations would be needed until the program produces 210001st prime ?
|
||||
Starting with the seed integer 2, successive iterations of the program produce the sequence:
|
||||
|
||||
$$15, 825, 725, 1925, 2275, 425, \ldots, 68, \mathbf{4}, 30, \ldots, 136, \mathbf{8}, 60, \ldots, 544, \mathbf{32}, 240, \ldots$$
|
||||
|
||||
The powers of 2 that appear in this sequence are $2^2, 2^3, 2^5, \ldots$.
|
||||
|
||||
It can be shown that all the powers of 2 in this sequence have prime exponents and that all the primes appear as exponents of powers of 2, in proper order!
|
||||
|
||||
If someone uses the above Fractran program to solve Project Euler Problem 7 (find the ${10001}^{\text{st}}$ prime), how many iterations would be needed until the program produces $2^{10001^{\text{st}}\text{ prime}}$?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler308()` should return 1539669807660924.
|
||||
`primeGeneratingAutomation()` should return `1539669807660924`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler308(), 1539669807660924);
|
||||
assert.strictEqual(primeGeneratingAutomation(), 1539669807660924);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -31,12 +39,12 @@ assert.strictEqual(euler308(), 1539669807660924);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler308() {
|
||||
function primeGeneratingAutomation() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler308();
|
||||
primeGeneratingAutomation();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,20 +8,22 @@ dashedName: problem-309-integer-ladders
|
||||
|
||||
# --description--
|
||||
|
||||
In the classic "Crossing Ladders" problem, we are given the lengths x and y of two ladders resting on the opposite walls of a narrow, level street. We are also given the height h above the street where the two ladders cross and we are asked to find the width of the street (w).
|
||||
In the classic "Crossing Ladders" problem, we are given the lengths $x$ and $y$ of two ladders resting on the opposite walls of a narrow, level street. We are also given the height $h$ above the street where the two ladders cross and we are asked to find the width of the street ($w$).
|
||||
|
||||
Here, we are only concerned with instances where all four variables are positive integers. For example, if x = 70, y = 119 and h = 30, we can calculate that w = 56.
|
||||
<img class="img-responsive center-block" alt="ladders x and y, crossing at the height h, and resting on opposite walls of the street of width w" src="https://cdn.freecodecamp.org/curriculum/project-euler/integer-ladders.gif" style="background-color: white; padding: 10px;">
|
||||
|
||||
In fact, for integer values x, y, h and 0 < x < y < 200, there are only five triplets (x,y,h) producing integer solutions for w: (70, 119, 30), (74, 182, 21), (87, 105, 35), (100, 116, 35) and (119, 175, 40).
|
||||
Here, we are only concerned with instances where all four variables are positive integers. For example, if $x = 70$, $y = 119$ and $h = 30$, we can calculate that $w = 56$.
|
||||
|
||||
For integer values x, y, h and 0 < x < y < 1 000 000, how many triplets (x,y,h) produce integer solutions for w?
|
||||
In fact, for integer values $x$, $y$, $h$ and $0 < x < y < 200$, there are only five triplets ($x$, $y$, $h$) producing integer solutions for $w$: (70, 119, 30), (74, 182, 21), (87, 105, 35), (100, 116, 35) and (119, 175, 40).
|
||||
|
||||
For integer values $x$, $y$, $h$ and $0 < x < y < 1\\,000\\,000$, how many triplets ($x$, $y$, $h$) produce integer solutions for $w$?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler309()` should return 210139.
|
||||
`integerLadders()` should return `210139`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler309(), 210139);
|
||||
assert.strictEqual(integerLadders(), 210139);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -29,12 +31,12 @@ assert.strictEqual(euler309(), 210139);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler309() {
|
||||
function integerLadders() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler309();
|
||||
integerLadders();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -12,18 +12,18 @@ Alice and Bob play the game Nim Square.
|
||||
|
||||
Nim Square is just like ordinary three-heap normal play Nim, but the players may only remove a square number of stones from a heap.
|
||||
|
||||
The number of stones in the three heaps is represented by the ordered triple (a,b,c).
|
||||
The number of stones in the three heaps is represented by the ordered triple ($a$, $b$, $c$).
|
||||
|
||||
If 0≤a≤b≤c≤29 then the number of losing positions for the next player is 1160.
|
||||
If $0 ≤ a ≤ b ≤ c ≤ 29$ then the number of losing positions for the next player is 1160.
|
||||
|
||||
Find the number of losing positions for the next player if 0≤a≤b≤c≤100 000.
|
||||
Find the number of losing positions for the next player if $0 ≤ a ≤ b ≤ c ≤ 100\\,000$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler310()` should return 2586528661783.
|
||||
`nimSquare()` should return `2586528661783`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler310(), 2586528661783);
|
||||
assert.strictEqual(nimSquare(), 2586528661783);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -31,12 +31,12 @@ assert.strictEqual(euler310(), 2586528661783);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler310() {
|
||||
function nimSquare() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler310();
|
||||
nimSquare();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,24 +8,26 @@ dashedName: problem-311-biclinic-integral-quadrilaterals
|
||||
|
||||
# --description--
|
||||
|
||||
ABCD is a convex, integer sided quadrilateral with 1 ≤ AB < BC < CD < AD.
|
||||
$ABCD$ is a convex, integer sided quadrilateral with $1 ≤ AB < BC < CD < AD$.
|
||||
|
||||
BD has integer length. O is the midpoint of BD. AO has integer length.
|
||||
$BD$ has integer length. $O$ is the midpoint of $BD$. $AO$ has integer length.
|
||||
|
||||
We'll call ABCD a biclinic integral quadrilateral if AO = CO ≤ BO = DO.
|
||||
We'll call $ABCD$ a biclinic integral quadrilateral if $AO = CO ≤ BO = DO$.
|
||||
|
||||
For example, the following quadrilateral is a biclinic integral quadrilateral: AB = 19, BC = 29, CD = 37, AD = 43, BD = 48 and AO = CO = 23.
|
||||
For example, the following quadrilateral is a biclinic integral quadrilateral: $AB = 19$, $BC = 29$, $CD = 37$, $AD = 43$, $BD = 48$ and $AO = CO = 23$.
|
||||
|
||||
Let B(N) be the number of distinct biclinic integral quadrilaterals ABCD that satisfy AB2+BC2+CD2+AD2 ≤ N. We can verify that B(10 000) = 49 and B(1 000 000) = 38239.
|
||||
<img class="img-responsive center-block" alt="quadrilateral ABCD, with point O, an midpoint of BD" src="https://cdn.freecodecamp.org/curriculum/project-euler/biclinic-integral-quadrilaterals.gif" style="background-color: white; padding: 10px;">
|
||||
|
||||
Find B(10 000 000 000).
|
||||
Let $B(N)$ be the number of distinct biclinic integral quadrilaterals $ABCD$ that satisfy ${AB}^2 + {BC}^2 + {CD}^2 + {AD}^2 ≤ N$. We can verify that $B(10\\,000) = 49$ and $B(1\\,000\\,000) = 38239$.
|
||||
|
||||
Find $B(10\\,000\\,000\\,000)$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler311()` should return 2466018557.
|
||||
`biclinicIntegralQuadrilaterals()` should return `2466018557`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler311(), 2466018557);
|
||||
assert.strictEqual(biclinicIntegralQuadrilaterals(), 2466018557);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -33,12 +35,12 @@ assert.strictEqual(euler311(), 2466018557);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler311() {
|
||||
function biclinicIntegralQuadrilaterals() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler311();
|
||||
biclinicIntegralQuadrilaterals();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,22 +8,32 @@ dashedName: problem-312-cyclic-paths-on-sierpiski-graphs
|
||||
|
||||
# --description--
|
||||
|
||||
\- A Sierpiński graph of order-1 (S1) is an equilateral triangle.
|
||||
- A Sierpiński graph of order-1 ($S_1$) is an equilateral triangle.
|
||||
- $S_{n + 1}$ is obtained from $S_n$ by positioning three copies of $S_n$ so that every pair of copies has one common corner.
|
||||
|
||||
\- Sn+1 is obtained from Sn by positioning three copies of Sn so that every pair of copies has one common corner.
|
||||
<img class="img-responsive center-block" alt="Sierpinski graphs of order-1 to order-5" src="https://cdn.freecodecamp.org/curriculum/project-euler/cyclic-paths-on-sierpinski-graphs-1.gif" style="background-color: white; padding: 10px;">
|
||||
|
||||
Let C(n) be the number of cycles that pass exactly once through all the vertices of Sn. For example, C(3) = 8 because eight such cycles can be drawn on S3, as shown below:
|
||||
Let $C(n)$ be the number of cycles that pass exactly once through all the vertices of $S_n$. For example, $C(3) = 8$ because eight such cycles can be drawn on $S_3$, as shown below:
|
||||
|
||||
It can also be verified that : C(1) = C(2) = 1 C(5) = 71328803586048 C(10 000) mod 108 = 37652224 C(10 000) mod 138 = 617720485
|
||||
<img class="img-responsive center-block" alt="eight cycles that pass exactly once through all vertices of S_3" src="https://cdn.freecodecamp.org/curriculum/project-euler/cyclic-paths-on-sierpinski-graphs-2.gif" style="background-color: white; padding: 10px;">
|
||||
|
||||
Find C(C(C(10 000))) mod 138.
|
||||
It can also be verified that:
|
||||
|
||||
$$\begin{align}
|
||||
& C(1) = C(2) = 1 \\\\
|
||||
& C(5) = 71\\,328\\,803\\,586\\,048 \\\\
|
||||
& C(10 000)\bmod {10}^8 = 37\\,652\\,224 \\\\
|
||||
& C(10 000)\bmod {13}^8 = 617\\,720\\,485 \\\\
|
||||
\end{align}$$
|
||||
|
||||
Find $C(C(C(10\\,000)))\bmod {13}^8$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler312()` should return 324681947.
|
||||
`pathsOnSierpinskiGraphs()` should return `324681947`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler312(), 324681947);
|
||||
assert.strictEqual(pathsOnSierpinskiGraphs(), 324681947);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -31,12 +41,12 @@ assert.strictEqual(euler312(), 324681947);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler312() {
|
||||
function pathsOnSierpinskiGraphs() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler312();
|
||||
pathsOnSierpinskiGraphs();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,18 +10,22 @@ dashedName: problem-313-sliding-game
|
||||
|
||||
In a sliding game a counter may slide horizontally or vertically into an empty space. The objective of the game is to move the red counter from the top left corner of a grid to the bottom right corner; the space always starts in the bottom right corner. For example, the following sequence of pictures show how the game can be completed in five moves on a 2 by 2 grid.
|
||||
|
||||
Let S(m,n) represent the minimum number of moves to complete the game on an m by n grid. For example, it can be verified that S(5,4) = 25.
|
||||
<img class="img-responsive center-block" alt="completing game in five moves on grid 2x2" src="https://cdn.freecodecamp.org/curriculum/project-euler/sliding-game-1.gif" style="background-color: white; padding: 10px;">
|
||||
|
||||
There are exactly 5482 grids for which S(m,n) = p2, where p < 100 is prime.
|
||||
Let $S(m, n)$ represent the minimum number of moves to complete the game on an $m$ by $n$ grid. For example, it can be verified that $S(5, 4) = 25$.
|
||||
|
||||
How many grids does S(m,n) = p2, where p < 106 is prime?
|
||||
<img class="img-responsive center-block" alt="initial grid state and final grid state for game on grid 5x4" src="https://cdn.freecodecamp.org/curriculum/project-euler/sliding-game-2.gif" style="background-color: white; padding: 10px;">
|
||||
|
||||
There are exactly 5482 grids for which $S(m, n) = p^2$, where $p < 100$ is prime.
|
||||
|
||||
How many grids does $S(m, n) = p^2$, where $p < {10}^6$ is prime?
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler313()` should return 2057774861813004.
|
||||
`slidingGame()` should return `2057774861813004`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler313(), 2057774861813004);
|
||||
assert.strictEqual(slidingGame(), 2057774861813004);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -29,12 +33,12 @@ assert.strictEqual(euler313(), 2057774861813004);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler313() {
|
||||
function slidingGame() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler313();
|
||||
slidingGame();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -10,20 +10,24 @@ dashedName: problem-314-the-mouse-on-the-moon
|
||||
|
||||
The moon has been opened up, and land can be obtained for free, but there is a catch. You have to build a wall around the land that you stake out, and building a wall on the moon is expensive. Every country has been allotted a 500 m by 500 m square area, but they will possess only that area which they wall in. 251001 posts have been placed in a rectangular grid with 1 meter spacing. The wall must be a closed series of straight lines, each line running from post to post.
|
||||
|
||||
The bigger countries of course have built a 2000 m wall enclosing the entire 250 000 m2 area. The Duchy of Grand Fenwick, has a tighter budget, and has asked you (their Royal Programmer) to compute what shape would get best maximum enclosed-area/wall-length ratio.
|
||||
The bigger countries of course have built a 2000 m wall enclosing the entire 250 000 $\text{m}^2$ area. The Duchy of Grand Fenwick, has a tighter budget, and has asked you (their Royal Programmer) to compute what shape would get best maximum $\frac{\text{enclosed-area}}{\text{wall-length}}$ ratio.
|
||||
|
||||
You have done some preliminary calculations on a sheet of paper. For a 2000 meter wall enclosing the 250 000 m2 area the enclosed-area/wall-length ratio is 125. Although not allowed , but to get an idea if this is anything better: if you place a circle inside the square area touching the four sides the area will be equal to π*2502 m2 and the perimeter will be π*500 m, so the enclosed-area/wall-length ratio will also be 125.
|
||||
You have done some preliminary calculations on a sheet of paper. For a 2000 meter wall enclosing the 250 000 $\text{m}^2$ area the $\frac{\text{enclosed-area}}{\text{wall-length}}$ ratio is 125.
|
||||
|
||||
However, if you cut off from the square four triangles with sides 75 m, 75 m and 75√2 m the total area becomes 238750 m2 and the perimeter becomes 1400+300√2 m. So this gives an enclosed-area/wall-length ratio of 130.87, which is significantly better.
|
||||
Although not allowed, but to get an idea if this is anything better: if you place a circle inside the square area touching the four sides the area will be equal to $π \times {250}^2 \text{m}^2$ and the perimeter will be $π \times 500 \text{m}$, so the $\frac{\text{enclosed-area}}{\text{wall-length}}$ ratio will also be 125.
|
||||
|
||||
Find the maximum enclosed-area/wall-length ratio. Give your answer rounded to 8 places behind the decimal point in the form abc.defghijk.
|
||||
However, if you cut off from the square four triangles with sides 75 m, 75 m and $75\sqrt{2}$ m the total area becomes 238750 $\text{m}^2$ and the perimeter becomes $1400 + 300\sqrt{2}$ m. So this gives an $\frac{\text{enclosed-area}}{\text{wall-length}}$ ratio of 130.87, which is significantly better.
|
||||
|
||||
<img class="img-responsive center-block" alt="picture showing difference in encosed-area between circle and square with cut off four triangles" src="https://cdn.freecodecamp.org/curriculum/project-euler/the-mouse-on-the-moon.gif" style="background-color: white; padding: 10px;">
|
||||
|
||||
Find the maximum $\frac{\text{enclosed-area}}{\text{wall-length}}$ ratio. Give your answer rounded to 8 places behind the decimal point in the form abc.defghijk.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler314()` should return 132.52756426.
|
||||
`theMouseOnTheMoon()` should return `132.52756426`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler314(), 132.52756426);
|
||||
assert.strictEqual(theMouseOnTheMoon(), 132.52756426);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -31,12 +35,12 @@ assert.strictEqual(euler314(), 132.52756426);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler314() {
|
||||
function theMouseOnTheMoon() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler314();
|
||||
theMouseOnTheMoon();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,34 +8,48 @@ dashedName: problem-315-digital-root-clocks
|
||||
|
||||
# --description--
|
||||
|
||||
<img class="img-responsive center-block" alt="animation of Sam's and Max's clocks calculating digital roots starting from 137" src="https://cdn.freecodecamp.org/curriculum/project-euler/digital-root-clocks.gif" style="background-color: white; padding: 10px;">
|
||||
|
||||
Sam and Max are asked to transform two digital clocks into two "digital root" clocks.
|
||||
|
||||
A digital root clock is a digital clock that calculates digital roots step by step.
|
||||
|
||||
When a clock is fed a number, it will show it and then it will start the calculation, showing all the intermediate values until it gets to the result. For example, if the clock is fed the number 137, it will show: "137" → "11" → "2" and then it will go black, waiting for the next number.
|
||||
When a clock is fed a number, it will show it and then it will start the calculation, showing all the intermediate values until it gets to the result. For example, if the clock is fed the number 137, it will show: `137` → `11` → `2` and then it will go black, waiting for the next number.
|
||||
|
||||
Every digital number consists of some light segments: three horizontal (top, middle, bottom) and four vertical (top-left, top-right, bottom-left, bottom-right). Number "1" is made of vertical top-right and bottom-right, number "4" is made by middle horizontal and vertical top-left, top-right and bottom-right. Number "8" lights them all.
|
||||
Every digital number consists of some light segments: three horizontal (top, middle, bottom) and four vertical (top-left, top-right, bottom-left, bottom-right). Number `1` is made of vertical top-right and bottom-right, number `4` is made by middle horizontal and vertical top-left, top-right and bottom-right. Number `8` lights them all.
|
||||
|
||||
The clocks consume energy only when segments are turned on/off. To turn on a "2" will cost 5 transitions, while a "7" will cost only 4 transitions.
|
||||
The clocks consume energy only when segments are turned on/off. To turn on a `2` will cost 5 transitions, while a `7` will cost only 4 transitions.
|
||||
|
||||
Sam and Max built two different clocks.
|
||||
|
||||
Sam's clock is fed e.g. number 137: the clock shows "137", then the panel is turned off, then the next number ("11") is turned on, then the panel is turned off again and finally the last number ("2") is turned on and, after some time, off. For the example, with number 137, Sam's clock requires:"137" : (2 + 5 + 4) × 2 = 22 transitions ("137" on/off). "11" : (2 + 2) × 2 = 8 transitions ("11" on/off). "2" : (5) × 2 = 10 transitions ("2" on/off).
|
||||
Sam's clock is fed e.g. number 137: the clock shows `137`, then the panel is turned off, then the next number (`11`) is turned on, then the panel is turned off again and finally the last number (`2`) is turned on and, after some time, off.
|
||||
|
||||
For the example, with number 137, Sam's clock requires:
|
||||
|
||||
- `137`: $(2 + 5 + 4) × 2 = 22$ transitions (`137` on/off).
|
||||
- `11`: $(2 + 2) × 2 = 8$ transitions (`11` on/off).
|
||||
- `2`: $(5) × 2 = 10$ transitions (`2` on/off).
|
||||
|
||||
For a grand total of 40 transitions.
|
||||
|
||||
Max's clock works differently. Instead of turning off the whole panel, it is smart enough to turn off only those segments that won't be needed for the next number. For number 137, Max's clock requires:"137" : 2 + 5 + 4 = 11 transitions ("137" on) 7 transitions (to turn off the segments that are not needed for number "11"). "11" : 0 transitions (number "11" is already turned on correctly) 3 transitions (to turn off the first "1" and the bottom part of the second "1"; the top part is common with number "2"). "2" : 4 transitions (to turn on the remaining segments in order to get a "2") 5 transitions (to turn off number "2").
|
||||
Max's clock works differently. Instead of turning off the whole panel, it is smart enough to turn off only those segments that won't be needed for the next number.
|
||||
|
||||
For number 137, Max's clock requires:
|
||||
|
||||
- `137` : $2 + 5 + 4 = 11$ transitions (`137` on), $7$ transitions (to turn off the segments that are not needed for number `11`).
|
||||
- `11` : $0$ transitions (number `11` is already turned on correctly), $3$ transitions (to turn off the first `1` and the bottom part of the second `1`; the top part is common with number `2`).
|
||||
- `2` : $4$ transitions (to turn on the remaining segments in order to get a `2`), $5$ transitions (to turn off number `2`).
|
||||
|
||||
For a grand total of 30 transitions.
|
||||
|
||||
Of course, Max's clock consumes less power than Sam's one. The two clocks are fed all the prime numbers between A = 107 and B = 2×107. Find the difference between the total number of transitions needed by Sam's clock and that needed by Max's one.
|
||||
Of course, Max's clock consumes less power than Sam's one. The two clocks are fed all the prime numbers between $A = {10}^7$ and $B = 2 × {10}^7$. Find the difference between the total number of transitions needed by Sam's clock and that needed by Max's one.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler315()` should return 13625242.
|
||||
`digitalRootClocks()` should return `13625242`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler315(), 13625242);
|
||||
assert.strictEqual(digitalRootClocks(), 13625242);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -43,12 +57,12 @@ assert.strictEqual(euler315(), 13625242);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler315() {
|
||||
function digitalRootClocks() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler315();
|
||||
digitalRootClocks();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,26 +8,34 @@ dashedName: problem-316-numbers-in-decimal-expansions
|
||||
|
||||
# --description--
|
||||
|
||||
Let p = p1 p2 p3 ... be an infinite sequence of random digits, selected from {0,1,2,3,4,5,6,7,8,9} with equal probability.
|
||||
Let $p = p_1 p_2 p_3 \ldots$ be an infinite sequence of random digits, selected from {0,1,2,3,4,5,6,7,8,9} with equal probability.
|
||||
|
||||
It can be seen that p corresponds to the real number 0.p1 p2 p3 ....
|
||||
It can be seen that $p$ corresponds to the real number $0.p_1 p_2 p_3 \ldots$.
|
||||
|
||||
It can also be seen that choosing a random real number from the interval \[0,1) is equivalent to choosing an infinite sequence of random digits selected from {0,1,2,3,4,5,6,7,8,9} with equal probability.
|
||||
It can also be seen that choosing a random real number from the interval [0,1) is equivalent to choosing an infinite sequence of random digits selected from {0,1,2,3,4,5,6,7,8,9} with equal probability.
|
||||
|
||||
For any positive integer n with d decimal digits, let k be the smallest index such that pk, pk+1, ...pk+d-1 are the decimal digits of n, in the same order. Also, let g(n) be the expected value of k; it can be proven that g(n) is always finite and, interestingly, always an integer number.
|
||||
For any positive integer $n$ with $d$ decimal digits, let $k$ be the smallest index such that $p_k, p_{k + 1}, \ldots p_{k + d - 1}$ are the decimal digits of $n$, in the same order.
|
||||
|
||||
For example, if n = 535, then for p = 31415926535897...., we get k = 9 for p = 355287143650049560000490848764084685354..., we get k = 36 etc and we find that g(535) = 1008.
|
||||
Also, let $g(n)$ be the expected value of $k$; it can be proven that $g(n)$ is always finite and, interestingly, always an integer number.
|
||||
|
||||
Given that , find
|
||||
For example, if $n = 535$, then
|
||||
|
||||
Note: represents the floor function.
|
||||
for $p = 31415926\mathbf{535}897\ldots$, we get $k = 9$
|
||||
|
||||
for $p = 35528714365004956000049084876408468\mathbf{535}4\ldots$, we get $k = 36$
|
||||
|
||||
etc and we find that $g(535) = 1008$.
|
||||
|
||||
Given that $\displaystyle\sum_{n = 2}^{999} g\left(\left\lfloor\frac{{10}^6}{n}\right\rfloor\right) = 27280188$, find $\displaystyle\sum_{n = 2}^{999\\,999} g\left(\left\lfloor\frac{{10}^{16}}{n}\right\rfloor\right)$.
|
||||
|
||||
**Note:** $\lfloor x\rfloor$ represents the floor function.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler316()` should return 542934735751917760.
|
||||
`numbersInDecimalExpansion()` should return `542934735751917760`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler316(), 542934735751917760);
|
||||
assert.strictEqual(numbersInDecimalExpansion(), 542934735751917760);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -35,12 +43,12 @@ assert.strictEqual(euler316(), 542934735751917760);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler316() {
|
||||
function numbersInDecimalExpansion() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler316();
|
||||
numbersInDecimalExpansion();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,18 +8,18 @@ dashedName: problem-317-firecracker
|
||||
|
||||
# --description--
|
||||
|
||||
A firecracker explodes at a height of 100 m above level ground. It breaks into a large number of very small fragments, which move in every direction; all of them have the same initial velocity of 20 m/s.
|
||||
A firecracker explodes at a height of 100 m above level ground. It breaks into a large number of very small fragments, which move in every direction; all of them have the same initial velocity of 20 $\frac{\text{m}}{\text{s}}$.
|
||||
|
||||
We assume that the fragments move without air resistance, in a uniform gravitational field with g=9.81 m/s2.
|
||||
We assume that the fragments move without air resistance, in a uniform gravitational field with $g=9.81 \frac{\text{m}}{\text{s}^2}$.
|
||||
|
||||
Find the volume (in m3) of the region through which the fragments move before reaching the ground. Give your answer rounded to four decimal places.
|
||||
Find the volume (in $\text{m}^3$) of the region through which the fragments move before reaching the ground. Give your answer rounded to four decimal places.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler317()` should return 1856532.8455.
|
||||
`firecracker()` should return `1856532.8455`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler317(), 1856532.8455);
|
||||
assert.strictEqual(firecracker(), 1856532.8455);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -27,12 +27,12 @@ assert.strictEqual(euler317(), 1856532.8455);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler317() {
|
||||
function firecracker() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler317();
|
||||
firecracker();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,44 +8,37 @@ dashedName: problem-318-2011-nines
|
||||
|
||||
# --description--
|
||||
|
||||
Consider the real number √2+√3.
|
||||
Consider the real number $\sqrt{2} + \sqrt{3}$.
|
||||
|
||||
When we calculate the even powers of √2+√3
|
||||
When we calculate the even powers of $\sqrt{2} + \sqrt{3}$ we get:
|
||||
|
||||
we get:
|
||||
$$\begin{align}
|
||||
& {(\sqrt{2} + \sqrt{3})}^2 = 9.898979485566356\ldots \\\\
|
||||
& {(\sqrt{2} + \sqrt{3})}^4 = 97.98979485566356\ldots \\\\
|
||||
& {(\sqrt{2} + \sqrt{3})}^6 = 969.998969071069263\ldots \\\\
|
||||
& {(\sqrt{2} + \sqrt{3})}^8 = 9601.99989585502907\ldots \\\\
|
||||
& {(\sqrt{2} + \sqrt{3})}^{10} = 95049.999989479221\ldots \\\\
|
||||
& {(\sqrt{2} + \sqrt{3})}^{12} = 940897.9999989371855\ldots \\\\
|
||||
& {(\sqrt{2} + \sqrt{3})}^{14} = 9313929.99999989263\ldots \\\\
|
||||
& {(\sqrt{2} + \sqrt{3})}^{16} = 92198401.99999998915\ldots \\\\
|
||||
\end{align}$$
|
||||
|
||||
(√2+√3)2 = 9.898979485566356...
|
||||
It looks like that the number of consecutive nines at the beginning of the fractional part of these powers is non-decreasing. In fact it can be proven that the fractional part of ${(\sqrt{2} + \sqrt{3})}^{2n}$ approaches 1 for large $n$.
|
||||
|
||||
(√2+√3)4 = 97.98979485566356...
|
||||
Consider all real numbers of the form $\sqrt{p} + \sqrt{q}$ with $p$ and $q$ positive integers and $p < q$, such that the fractional part of ${(\sqrt{p} + \sqrt{q})}^{2n}$ approaches 1 for large $n$.
|
||||
|
||||
(√2+√3)6 = 969.998969071069263...
|
||||
Let $C(p,q,n)$ be the number of consecutive nines at the beginning of the fractional part of ${(\sqrt{p} + \sqrt{q})}^{2n}$.
|
||||
|
||||
(√2+√3)8 = 9601.99989585502907...
|
||||
Let $N(p,q)$ be the minimal value of $n$ such that $C(p,q,n) ≥ 2011$.
|
||||
|
||||
(√2+√3)10 = 95049.999989479221...
|
||||
|
||||
(√2+√3)12 = 940897.9999989371855...
|
||||
|
||||
(√2+√3)14 = 9313929.99999989263...
|
||||
|
||||
(√2+√3)16 = 92198401.99999998915...
|
||||
|
||||
It looks like that the number of consecutive nines at the beginning of the fractional part of these powers is non-decreasing. In fact it can be proven that the fractional part of (√2+√3)2n approaches 1 for large n.
|
||||
|
||||
Consider all real numbers of the form √p+√q with p and q positive integers and p<q, such that the fractional part of (√p+√q)2n approaches 1 for large n.
|
||||
|
||||
Let C(p,q,n) be the number of consecutive nines at the beginning of the fractional part of (√p+√q)2n.
|
||||
|
||||
Let N(p,q) be the minimal value of n such that C(p,q,n) ≥ 2011.
|
||||
|
||||
Find ∑N(p,q) for p+q ≤ 2011.
|
||||
Find $\sum N(p,q)$ for $p + q ≤ 2011$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler318()` should return 709313889.
|
||||
`twoThousandElevenNines()` should return `709313889`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler318(), 709313889);
|
||||
assert.strictEqual(twoThousandElevenNines(), 709313889);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -53,12 +46,12 @@ assert.strictEqual(euler318(), 709313889);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler318() {
|
||||
function twoThousandElevenNines() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler318();
|
||||
twoThousandElevenNines();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,26 +8,24 @@ dashedName: problem-319-bounded-sequences
|
||||
|
||||
# --description--
|
||||
|
||||
Let x1, x2,..., xn be a sequence of length n such that:
|
||||
Let $x_1, x_2, \ldots, x_n$ be a sequence of length $n$ such that:
|
||||
|
||||
x1 = 2
|
||||
|
||||
for all 1 < i ≤ n : xi-1 < xi
|
||||
|
||||
for all i and j with 1 ≤ i, j ≤ n : (xi) j < (xj + 1)i
|
||||
- $x_1 = 2$
|
||||
- for all $1 < i ≤ n : x_{i - 1} < x_i$
|
||||
- for all $i$ and $j$ with $1 ≤ i, j ≤ n : {(x_i)}^j < {(x_j + 1)}^i$
|
||||
|
||||
There are only five such sequences of length 2, namely: {2,4}, {2,5}, {2,6}, {2,7} and {2,8}. There are 293 such sequences of length 5; three examples are given below: {2,5,11,25,55}, {2,6,14,36,88}, {2,8,22,64,181}.
|
||||
|
||||
Let t(n) denote the number of such sequences of length n. You are given that t(10) = 86195 and t(20) = 5227991891.
|
||||
Let $t(n)$ denote the number of such sequences of length $n$. You are given that $t(10) = 86195$ and $t(20) = 5227991891$.
|
||||
|
||||
Find t(1010) and give your answer modulo 109.
|
||||
Find $t({10}^{10})$ and give your answer modulo $10^9$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler319()` should return 268457129.
|
||||
`boundedSequences()` should return `268457129`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler319(), 268457129);
|
||||
assert.strictEqual(boundedSequences(), 268457129);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -35,12 +33,12 @@ assert.strictEqual(euler319(), 268457129);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler319() {
|
||||
function boundedSequences() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler319();
|
||||
boundedSequences();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -8,20 +8,20 @@ dashedName: problem-320-factorials-divisible-by-a-huge-integer
|
||||
|
||||
# --description--
|
||||
|
||||
Let N(i) be the smallest integer n such that n! is divisible by (i!)1234567890
|
||||
Let $N(i)$ be the smallest integer $n$ such that $n!$ is divisible by $(i!)^{1234567890}$
|
||||
|
||||
Let S(u)=∑N(i) for 10 ≤ i ≤ u.
|
||||
Let $S(u) = \sum N(i)$ for $10 ≤ i ≤ u$.
|
||||
|
||||
S(1000)=614538266565663.
|
||||
$S(1000)=614\\,538\\,266\\,565\\,663$.
|
||||
|
||||
Find S(1 000 000) mod 1018.
|
||||
Find $S(1\\,000\\,000)\bmod {10}^{18}$.
|
||||
|
||||
# --hints--
|
||||
|
||||
`euler320()` should return 278157919195482660.
|
||||
`divisibleByHugeInteger()` should return `278157919195482660`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(euler320(), 278157919195482660);
|
||||
assert.strictEqual(divisibleByHugeInteger(), 278157919195482660);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
@ -29,12 +29,12 @@ assert.strictEqual(euler320(), 278157919195482660);
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function euler320() {
|
||||
function divisibleByHugeInteger() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
euler320();
|
||||
divisibleByHugeInteger();
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
Reference in New Issue
Block a user