id int64 1 981 | problem stringlengths 97 5.29k | raw_html stringlengths 121 5.63k | url stringlengths 34 36 | answer stringlengths 1 29 |
|---|---|---|---|---|
301 | Nim is a game played with heaps of stones, where two players take it in turn to remove any number of stones from any heap until no stones remain.
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 each player's turn, the player may remove any positive number of stones from any single heap.
- The first player unable to move (because no stones remain) loses.
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, which you may look up or attempt to deduce for yourself, $X(n_1,n_2,n_3)$ 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, the 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 the 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 \le 2^{30}$ does $X(n,2n,3n) = 0$ ? | <p><dfn>Nim</dfn> is a game played with heaps of stones, where two players take it in turn to remove any number of stones from any heap until no stones remain.</p>
<p>We'll consider the three-heap normal-play version of Nim, which works as follows:</p>
<ul>
<li>At the start of the game there are three heaps of stones.</li>
<li>On each player's turn, the player may remove any positive number of stones from any single heap.</li>
<li>The first player unable to move (because no stones remain) loses.</li>
</ul>
<p>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, which you may look up or attempt to deduce for yourself, $X(n_1,n_2,n_3)$ that returns:</p>
<ul>
<li>zero if, with perfect strategy, the player about to move will eventually lose; or</li>
<li>non-zero if, with perfect strategy, the player about to move will eventually win.</li>
</ul>
<p>For example $X(1,2,3) = 0$ because, no matter what the current player does, the 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 the opponent until no stones remain; so the current player loses. To illustrate:</p>
<ul>
<li>current player moves to $(1,2,1)$</li>
<li>opponent moves to $(1,0,1)$</li>
<li>current player moves to $(0,0,1)$</li>
<li>opponent moves to $(0,0,0)$, and so wins.</li>
</ul>
<p>For how many positive integers $n \le 2^{30}$ does $X(n,2n,3n) = 0$ ?</p> | https://projecteuler.net/problem=301 | 2178309 |
302 | 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 an Achilles number if $n$ is powerful but not a perfect power. For example, $864$ and $1800$ are Achilles numbers: $864 = 2^5 \cdot 3^3$ and $1800 = 2^3 \cdot 3^2 \cdot 5^2$.
We shall call a positive integer $S$ a Strong Achilles number if both $S$ and $\phi(S)$ are Achilles numbers.1
For example, $864$ is a Strong Achilles number: $\phi(864) = 288 = 2^5 \cdot 3^2$. However, $1800$ isn't a Strong Achilles number because: $\phi(1800) = 480 = 2^5 \cdot 3^1 \cdot 5^1$.
There are $7$ Strong Achilles numbers below $10^4$ and $656$ below $10^8$.
How many Strong Achilles numbers are there below $10^{18}$?
1 $\phi$ denotes Euler's totient function. | <p>
A positive integer $n$ is <strong>powerful</strong> if $p^2$ is a divisor of $n$ for every prime factor $p$ in $n$.
</p>
<p>
A positive integer $n$ is a <strong>perfect power</strong> if $n$ can be expressed as a power of another positive integer.
</p>
<p>
A positive integer $n$ is an <strong>Achilles number</strong> if $n$ is powerful but not a perfect power. For example, $864$ and $1800$ are Achilles numbers: $864 = 2^5 \cdot 3^3$ and $1800 = 2^3 \cdot 3^2 \cdot 5^2$.
</p>
<p>
We shall call a positive integer $S$ a <dfn>Strong Achilles number</dfn> if both $S$ and $\phi(S)$ are Achilles numbers.<sup>1</sup><br>
For example, $864$ is a Strong Achilles number: $\phi(864) = 288 = 2^5 \cdot 3^2$. However, $1800$ isn't a Strong Achilles number because: $\phi(1800) = 480 = 2^5 \cdot 3^1 \cdot 5^1$.
</p>
<p>There are $7$ Strong Achilles numbers below $10^4$ and $656$ below $10^8$.
</p>
<p>
How many Strong Achilles numbers are there below $10^{18}$?
</p>
<p>
<sup>1</sup> $\phi$ denotes <strong>Euler's totient function</strong>.
</p> | https://projecteuler.net/problem=302 | 1170060 |
303 | For a positive integer $n$, define $f(n)$ as the least positive multiple of $n$ that, written in base $10$, uses only digits $\le 2$.
Thus $f(2)=2$, $f(3)=12$, $f(7)=21$, $f(42)=210$, $f(89)=1121222$.
Also, $\sum \limits_{n = 1}^{100} {\dfrac{f(n)}{n}} = 11363107$.
Find $\sum \limits_{n=1}^{10000} {\dfrac{f(n)}{n}}$. | <p>
For a positive integer $n$, define $f(n)$ as the least positive multiple of $n$ that, written in base $10$, uses only digits $\le 2$.</p>
<p>Thus $f(2)=2$, $f(3)=12$, $f(7)=21$, $f(42)=210$, $f(89)=1121222$.</p>
<p>Also, $\sum \limits_{n = 1}^{100} {\dfrac{f(n)}{n}} = 11363107$.</p>
<p>
Find $\sum \limits_{n=1}^{10000} {\dfrac{f(n)}{n}}$.
</p> | https://projecteuler.net/problem=303 | 1111981904675169 |
304 | For any positive integer $n$ the function $\operatorname{next\_prime}(n)$ returns the smallest prime $p$ such that $p \gt n$.
The sequence $a(n)$ is defined by:
$a(1)=\operatorname{next\_prime}(10^{14})$ and $a(n)=\operatorname{next\_prime}(a(n-1))$ for $n \gt 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 \gt 1$.
The sequence $b(n)$ is defined as $f(a(n))$.
Find $\sum b(n)$ for $1 \le n \le 100\,000$.
Give your answer mod $1234567891011$. | <p>
For any positive integer $n$ the function $\operatorname{next\_prime}(n)$ returns the smallest prime $p$ such that $p \gt n$.
</p>
<p>
The sequence $a(n)$ is defined by:<br>
$a(1)=\operatorname{next\_prime}(10^{14})$ and $a(n)=\operatorname{next\_prime}(a(n-1))$ for $n \gt 1$.
</p>
<p>
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 \gt 1$.
</p>
<p>
The sequence $b(n)$ is defined as $f(a(n))$.
</p>
<p>
Find $\sum b(n)$ for $1 \le n \le 100\,000$.
Give your answer mod $1234567891011$.
</p> | https://projecteuler.net/problem=304 | 283988410192 |
305 | 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\cdots$
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 $n$th occurrence of $n$ in $S$.
For example, $f(1)=1$, $f(5)=81$, $f(12)=271$ and $f(7780)=111111365$.
Find $\sum f(3^k)$ for $1 \le k \le 13$. | <p>
Let's call $S$ the (infinite) string that is made by concatenating the consecutive positive integers (starting from $1$) written down in base $10$.<br>
Thus, $S = 1234567891011121314151617181920212223242\cdots$
</p>
<p>
It's easy to see that any number will show up an infinite number of times in $S$.
</p>
<p>
Let's call $f(n)$ the starting position of the $n$<sup>th</sup> occurrence of $n$ in $S$.<br>
For example, $f(1)=1$, $f(5)=81$, $f(12)=271$ and $f(7780)=111111365$.
</p>
<p>
Find $\sum f(3^k)$ for $1 \le k \le 13$.
</p> | https://projecteuler.net/problem=305 | 18174995535140 |
306 | 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.
- $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$: 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 \le n \le 5$, there are 3 values of $n$ for which the first player can force a win.
Similarly, for $1 \le n \le 50$, there are 40 values of $n$ for which the first player can force a win.
For $1 \le n \le 1 000 000$, how many values of $n$ are there for which the first player can force a win? | <p>The following game is a classic example of Combinatorial Game Theory:</p>
<p>Two players start with a strip of $n$ white squares and they take alternate turns.<br>
On each turn, a player picks two contiguous white squares and paints them black.<br>
The first player who cannot make a move loses.</p>
<ul>
<li>$n = 1$: No valid moves, so the first player loses automatically.</li>
<li>$n = 2$: Only one valid move, after which the second player loses.</li>
<li>$n = 3$: Two valid moves, but both leave a situation where the second player loses.</li>
<li>$n = 4$: Three valid moves for the first player, who is able to win the game by painting the two middle squares.</li>
<li>$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.</li>
</ul>
<div class="center"><img src="resources/images/0306_pstrip.gif?1678992056" class="dark_img" alt="0306_pstrip.gif"></div>
<p>So, for $1 \le n \le 5$, there are 3 values of $n$ for which the first player can force a win.<br>
Similarly, for $1 \le n \le 50$, there are 40 values of $n$ for which the first player can force a win.</p>
<p>For $1 \le n \le 1 000 000$, how many values of $n$ are there for which the first player can force a win?</p> | https://projecteuler.net/problem=306 | 852938 |
307 | $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) \approx 0.0204081633$.
Find $p(20\,000, 1\,000\,000)$ and give your answer rounded to $10$ decimal places in the form 0.abcdefghij. | <p>
$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).
</p>
<p>
Let $p(k, n)$ represent the probability that there is a chip with at least $3$ defects.<br>
For instance $p(3,7) \approx 0.0204081633$.
</p>
<p>
Find $p(20\,000, 1\,000\,000)$ and give your answer rounded to $10$ decimal places in the form 0.abcdefghij.
</p> | https://projecteuler.net/problem=307 | 0.7311720251 |
308 | A program written in the programming language Fractran consists of a list of fractions.
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:
$$\dfrac{17}{91}, \dfrac{78}{85}, \dfrac{19}{51}, \dfrac{23}{38}, \dfrac{29}{33}, \dfrac{77}{29}, \dfrac{95}{23}, \dfrac{77}{19}, \dfrac{1}{17}, \dfrac{11}{13}, \dfrac{13}{11}, \dfrac{15}{2}, \dfrac{1}{7}, \dfrac{55}{1}$$
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, ...
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!
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 ? | <p>A program written in the programming language Fractran consists of a list of fractions.</p>
<p>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.</p>
<p>For example, one of the Fractran programs that John Horton Conway wrote for prime-generation consists of the following 14 fractions:</p>
<p>$$\dfrac{17}{91}, \dfrac{78}{85}, \dfrac{19}{51}, \dfrac{23}{38}, \dfrac{29}{33}, \dfrac{77}{29}, \dfrac{95}{23}, \dfrac{77}{19}, \dfrac{1}{17}, \dfrac{11}{13}, \dfrac{13}{11}, \dfrac{15}{2}, \dfrac{1}{7}, \dfrac{55}{1}$$</p>
<p>Starting with the seed integer 2, successive iterations of the program produce the sequence:<br>
15, 825, 725, 1925, 2275, 425, ..., 68, <b>4</b>, 30, ..., 136, <b>8</b>, 60, ..., 544, <b>32</b>, 240, ...</p>
<p>The powers of 2 that appear in this sequence are 2<sup>2</sup>, 2<sup>3</sup>, 2<sup>5</sup>, ...<br>
It can be shown that <i>all</i> the powers of 2 in this sequence have prime exponents and that <i>all</i> the primes appear as exponents of powers of 2, in proper order!</p>
<p>If someone uses the above Fractran program to solve Project Euler Problem 7 (find the 10001<sup>st</sup> prime), how many iterations would be needed until the program produces 2<sup>10001st prime</sup> ?</p> | https://projecteuler.net/problem=308 | 1539669807660924 |
309 | 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$.
In fact, for integer values $x$, $y$, $h$ and $0 \lt x \lt y \lt 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 \lt x \lt y \lt 1\,000\,000$, how many triplets $(x, y, h)$ produce integer solutions for $w$? | <p>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$).</p>
<div align="center"><img src="resources/images/0309_ladders.gif?1678992056" class="dark_img" alt="0309_ladders.gif"></div>
<p>Here, we are only concerned with instances where all four variables are positive integers.<br>
For example, if $x = 70$, $y = 119$ and $h = 30$, we can calculate that $w = 56$.</p>
<p>In fact, for integer values $x$, $y$, $h$ and $0 \lt x \lt y \lt 200$, there are only five triplets $(x, y, h)$ producing integer solutions for $w$:<br>
$(70, 119, 30)$, $(74, 182, 21)$, $(87, 105, 35)$, $(100, 116, 35)$ and $(119, 175, 40)$.</p>
<p>For integer values $x, y, h$ and $0 \lt x \lt y \lt 1\,000\,000$, how many triplets $(x, y, h)$ produce integer solutions for $w$?</p> | https://projecteuler.net/problem=309 | 210139 |
310 | 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)$.
If $0 \le a \le b \le c \le 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 \le a \le b \le c \le 100\,000$. | <p>
Alice and Bob play the game Nim Square.<br>
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.<br>
The number of stones in the three heaps is represented by the ordered triple $(a,b,c)$.<br>
If $0 \le a \le b \le c \le 29$ then the number of losing positions for the next player is $1160$.
</p>
<p>
Find the number of losing positions for the next player if $0 \le a \le b \le c \le 100\,000$.
</p> | https://projecteuler.net/problem=310 | 2586528661783 |
311 | $ABCD$ is a convex, integer sided quadrilateral with $1 \le AB \lt BC \lt CD \lt AD$.
$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 \le 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$.
Let $B(N)$ be the number of distinct biclinic integral quadrilaterals $ABCD$ that satisfy $AB^2+BC^2+CD^2+AD^2 \le N$.
We can verify that $B(10\,000) = 49$ and $B(1\,000\,000) = 38239$.
Find $B(10\,000\,000\,000)$. | <p>$ABCD$ is a convex, integer sided quadrilateral with $1 \le AB \lt BC \lt CD \lt AD$.<br>
$BD$ has integer length. $O$ is the midpoint of $BD$. $AO$ has integer length.<br>
We'll call $ABCD$ a <dfn>biclinic integral quadrilateral</dfn> if $AO = CO \le BO = DO$.<br></p>
<p>For example, the following quadrilateral is a biclinic integral quadrilateral:<br>
$AB = 19$, $BC = 29$, $CD = 37$, $AD = 43$, $BD = 48$ and $AO = CO = 23$.
</p>
<div align="center"><img src="resources/images/0311_biclinic.gif?1678992056" class="dark_img" alt="0311_biclinic.gif"></div>
<p>Let $B(N)$ be the number of distinct biclinic integral quadrilaterals $ABCD$ that satisfy $AB^2+BC^2+CD^2+AD^2 \le N$.<br>
We can verify that $B(10\,000) = 49$ and $B(1\,000\,000) = 38239$.
</p>
<p>Find $B(10\,000\,000\,000)$.
</p> | https://projecteuler.net/problem=311 | 2466018557 |
312 | - 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.
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) \bmod 10^8 = 37652224$
$C(10\,000) \bmod 13^8 = 617720485$
Find $C(C(C(10\,000))) \bmod 13^8$. | <p>- A <strong>Sierpiński graph</strong> of order-$1$ ($S_1$) is an equilateral triangle.<br>
- $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.
</p>
<div align="center"><img src="resources/images/0312_sierpinskyAt.gif?1678992056" class="dark_img" alt="0312_sierpinskyAt.gif"></div>
<p>Let $C(n)$ be the number of cycles that pass exactly once through all the vertices of $S_n$.<br>
For example, $C(3) = 8$ because eight such cycles can be drawn on $S_3$, as shown below:
</p>
<div align="center"><img src="resources/images/0312_sierpinsky8t.gif?1678992056" class="dark_img" alt="0312_sierpinsky8t.gif"></div>
<p>It can also be verified that :<br>
$C(1) = C(2) = 1$<br>
$C(5) = 71328803586048$<br>
$C(10\,000) \bmod 10^8 = 37652224$<br>
$C(10\,000) \bmod 13^8 = 617720485$<br></p>
<p>Find $C(C(C(10\,000))) \bmod 13^8$.
</p> | https://projecteuler.net/problem=312 | 324681947 |
313 | 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$.
There are exactly $5482$ grids for which $S(m,n) = p^2$, where $p \lt 100$ is prime.
How many grids does $S(m,n) = p^2$, where $p \lt 10^6$ is prime? | <p>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.</p>
<div align="center"><img src="resources/images/0313_sliding_game_1.gif?1678992056" alt="0313_sliding_game_1.gif"></div>
<p>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$.</p>
<div align="center"><img src="resources/images/0313_sliding_game_2.gif?1678992056" alt="0313_sliding_game_2.gif"></div>
<p>There are exactly $5482$ grids for which $S(m,n) = p^2$, where $p \lt 100$ is prime.</p>
<p>How many grids does $S(m,n) = p^2$, where $p \lt 10^6$ is prime?</p> | https://projecteuler.net/problem=313 | 2057774861813004 |
314 | 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 $\pu{500 m}$ by $\pu{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 $\pu{2000 m}$ wall enclosing the entire $\pu{250 000 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 enclosed-area/wall-length ratio.
You have done some preliminary calculations on a sheet of paper.
For a $2000$ meter wall enclosing the $\pu{250 000 m^2}$ 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 $\pi \times \pu{250^2 m^2}$ and the perimeter will be $\pi \times \pu{500 m}$, so the enclosed-area/wall-length ratio will also be $125$.
However, if you cut off from the square four triangles with sides $\pu{75 m}$, $\pu{75 m}$ and $75\pu{\sqrt 2 m}$ the total area becomes $\pu{238750 m^2}$ and the perimeter becomes $1400+300\pu{\sqrt 2 m}$. So this gives an enclosed-area/wall-length ratio of $130.87$, which is significantly better.
Find the maximum enclosed-area/wall-length ratio.
Give your answer rounded to $8$ places behind the decimal point in the form abc.defghijk. | <p>
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 $\pu{500 m}$ by $\pu{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.
</p>
<p>
The bigger countries of course have built a $\pu{2000 m}$ wall enclosing the entire $\pu{250 000 m^2}$ area. The <a href="http://en.wikipedia.org/wiki/Grand_Fenwick">Duchy of Grand Fenwick</a>, has a tighter budget, and has asked you (their Royal Programmer) to compute what shape would get best maximum enclosed-area/wall-length ratio.
</p>
<p>
You have done some preliminary calculations on a sheet of paper.
For a $2000$ meter wall enclosing the $\pu{250 000 m^2}$ area the
enclosed-area/wall-length ratio is $125$.<br>
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 $\pi \times \pu{250^2 m^2}$ and the perimeter will be $\pi \times \pu{500 m}$, so the enclosed-area/wall-length ratio will also be $125$.
</p>
<p>
However, if you cut off from the square four triangles with sides $\pu{75 m}$, $\pu{75 m}$ and $75\pu{\sqrt 2 m}$ the total area becomes $\pu{238750 m^2}$ and the perimeter becomes $1400+300\pu{\sqrt 2 m}$. So this gives an enclosed-area/wall-length ratio of $130.87$, which is significantly better.
</p>
<div align="center"><img src="resources/images/0314_landgrab.gif?1678992056" class="dark_img" alt="0314_landgrab.gif"></div>
<p>
Find the maximum enclosed-area/wall-length ratio.<br>
Give your answer rounded to $8$ places behind the decimal point in the form abc.defghijk.
</p> | https://projecteuler.net/problem=314 | 132.52756426 |
315 | 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.
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.
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). |
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"). |
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. | <p></p><div align="center"><img src="resources/images/0315_clocks.gif?1678992056" alt="0315_clocks.gif"></div>
<p>Sam and Max are asked to transform two digital clocks into two "digital root" clocks.<br>
A digital root clock is a digital clock that calculates digital roots step by step.</p>
<p>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.<br>
For example, if the clock is fed the number 137, it will show: "<b>137</b>" → "<b>11</b>" → "<b>2</b>" and then it will go black, waiting for the next number.</p>
<p>Every digital number consists of some light segments: three horizontal (top, middle, bottom) and four vertical (top-left, top-right, bottom-left, bottom-right).<br>
Number "<b>1</b>" is made of vertical top-right and bottom-right, number "<b>4</b>" is made by middle horizontal and vertical top-left, top-right and bottom-right. Number "<b>8</b>" lights them all.</p>
<p>The clocks consume energy only when segments are turned on/off.<br>
To turn on a "<b>2</b>" will cost 5 transitions, while a "<b>7</b>" will cost only 4 transitions.</p>
<p>Sam and Max built two different clocks.</p>
<p>Sam's clock is fed e.g. number 137: the clock shows "<b>137</b>", then the panel is turned off, then the next number ("<b>11</b>") is turned on, then the panel is turned off again and finally the last number ("<b>2</b>") is turned on and, after some time, off.<br>
For the example, with number 137, Sam's clock requires:<br></p><table><tr><td>"<b>137</b>"</td>
<td>:</td>
<td>(2 + 5 + 4) × 2 = 22 transitions ("<b>137</b>" on/off).</td>
</tr><tr><td>"<b>11</b>"</td>
<td>:</td>
<td>(2 + 2) × 2 = 8 transitions ("<b>11</b>" on/off).</td>
</tr><tr><td>"<b>2</b>"</td>
<td>:</td>
<td>(5) × 2 = 10 transitions ("<b>2</b>" on/off).</td>
</tr></table>
For a grand total of 40 transitions.
<p>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.<br>
For number 137, Max's clock requires:<br></p><table><tr><td>"<b>137</b>"<br><br></td>
<td>:<br><br></td>
<td>2 + 5 + 4 = 11 transitions ("<b>137</b>" on)<br>
7 transitions (to turn off the segments that are not needed for number "<b>11</b>").</td>
</tr><tr><td>"<b>11</b>"<br><br><br></td>
<td>:<br><br><br></td>
<td>0 transitions (number "<b>11</b>" is already turned on correctly)<br>
3 transitions (to turn off the first "<b>1</b>" and the bottom part of the second "<b>1</b>"; <br>
the top part is common with number "<b>2</b>").</td>
</tr><tr><td>"<b>2</b>"<br><br></td>
<td>:<br><br></td>
<td>4 transitions (to turn on the remaining segments in order to get a "<b>2</b>")<br>
5 transitions (to turn off number "<b>2</b>").</td>
</tr></table>
For a grand total of 30 transitions.
<p>Of course, Max's clock consumes less power than Sam's one.<br>
The two clocks are fed all the prime numbers between A = 10<sup>7</sup> and B = 2×10<sup>7</sup>. <br>
Find the difference between the total number of transitions needed by Sam's clock and that needed by Max's one.</p> | https://projecteuler.net/problem=315 | 13625242 |
316 | Let $p = p_1 p_2 p_3 \cdots$ 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.p_1 p_2 p_3 \cdots$
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 $p_k, p_{k + 1}, \dots, p_{k + 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 example, if $n = 535$, then
for $p = 31415926\mathbf{535}897\cdots$, we get $k = 9$
for $p = 35528714365004956000049084876408468\mathbf{535}4\cdots$, 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}^{999999} g \left(\left\lfloor\frac{10^{16}} n \right\rfloor\right)$.
Note: $\lfloor x \rfloor$ represents the floor function. | <p>Let $p = p_1 p_2 p_3 \cdots$ be an infinite sequence of random digits, selected from $\{0,1,2,3,4,5,6,7,8,9\}$ with equal probability.<br>
It can be seen that $p$ corresponds to the real number $0.p_1 p_2 p_3 \cdots$ <br>
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.</p>
<p>For any positive integer $n$ with $d$ decimal digits, let $k$ be the smallest index such that $p_k, p_{k + 1}, \dots, p_{k + d - 1}$ are the decimal digits of $n$, in the same order.<br>
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.</p>
<p>For example, if $n = 535$, then<br>
for $p = 31415926\mathbf{535}897\cdots$, we get $k = 9$<br>
for $p = 35528714365004956000049084876408468\mathbf{535}4\cdots$, we get $k = 36$<br>
etc and we find that $g(535) = 1008$.</p>
<p>Given that $\displaystyle\sum_{n = 2}^{999} g \left(\left\lfloor\frac{10^6} n \right\rfloor\right) = 27280188$, find $\displaystyle\sum_{n = 2}^{999999} g \left(\left\lfloor\frac{10^{16}} n \right\rfloor\right)$.</p>
<u><i>Note</i></u>: $\lfloor x \rfloor$ represents the floor function. | https://projecteuler.net/problem=316 | 542934735751917735 |
317 | A firecracker explodes at a height of $\pu{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 $\pu{20 m/s}$.
We assume that the fragments move without air resistance, in a uniform gravitational field with $g=\pu{9.81 m/s^2}$.
Find the volume (in $\pu{m^3}$) of the region through which the fragments move before reaching the ground.
Give your answer rounded to four decimal places. | <p>
A firecracker explodes at a height of $\pu{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 $\pu{20 m/s}$.
</p>
<p>
We assume that the fragments move without air resistance, in a uniform gravitational field with $g=\pu{9.81 m/s^2}$.
</p>
<p>
Find the volume (in $\pu{m^3}$) of the region through which the fragments move before reaching the ground.
Give your answer rounded to four decimal places.
</p> | https://projecteuler.net/problem=317 | 1856532.8455 |
318 | Consider the real number $\sqrt 2 + \sqrt 3$.
When we calculate the even powers of $\sqrt 2 + \sqrt 3$
we get:
$(\sqrt 2 + \sqrt 3)^2 = 9.898979485566356 \cdots $
$(\sqrt 2 + \sqrt 3)^4 = 97.98979485566356 \cdots $
$(\sqrt 2 + \sqrt 3)^6 = 969.998969071069263 \cdots $
$(\sqrt 2 + \sqrt 3)^8 = 9601.99989585502907 \cdots $
$(\sqrt 2 + \sqrt 3)^{10} = 95049.999989479221 \cdots $
$(\sqrt 2 + \sqrt 3)^{12} = 940897.9999989371855 \cdots $
$(\sqrt 2 + \sqrt 3)^{14} = 9313929.99999989263 \cdots $
$(\sqrt 2 + \sqrt 3)^{16} = 92198401.99999998915 \cdots $
It looks as if 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)^{2 n}$ approaches $1$ for large $n$.
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)^{ 2 n}$ approaches $1$ for large $n$.
Let $C(p,q,n)$ be the number of consecutive nines at the beginning of the fractional part of $(\sqrt p + \sqrt q)^{ 2 n}$.
Let $N(p,q)$ be the minimal value of $n$ such that $C(p,q,n) \ge 2011$.
Find $\displaystyle \sum N(p,q) \,\, \text{ for } p+q \le 2011$. | <p>
Consider the real number $\sqrt 2 + \sqrt 3$.<br>
When we calculate the even powers of $\sqrt 2 + \sqrt 3$
we get:<br>
$(\sqrt 2 + \sqrt 3)^2 = 9.898979485566356 \cdots $<br>
$(\sqrt 2 + \sqrt 3)^4 = 97.98979485566356 \cdots $<br>
$(\sqrt 2 + \sqrt 3)^6 = 969.998969071069263 \cdots $<br>
$(\sqrt 2 + \sqrt 3)^8 = 9601.99989585502907 \cdots $<br>
$(\sqrt 2 + \sqrt 3)^{10} = 95049.999989479221 \cdots $<br>
$(\sqrt 2 + \sqrt 3)^{12} = 940897.9999989371855 \cdots $<br>
$(\sqrt 2 + \sqrt 3)^{14} = 9313929.99999989263 \cdots $<br>
$(\sqrt 2 + \sqrt 3)^{16} = 92198401.99999998915 \cdots $<br></p>
<p>
It looks as if the number of consecutive nines at the beginning of the fractional part of these powers is non-decreasing.<br>
In fact it can be proven that the fractional part of $(\sqrt 2 + \sqrt 3)^{2 n}$ approaches $1$ for large $n$.
</p>
<p>
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)^{ 2 n}$ approaches $1$ for large $n$.
</p>
<p>
Let $C(p,q,n)$ be the number of consecutive nines at the beginning of the fractional part of $(\sqrt p + \sqrt q)^{ 2 n}$.
</p>
<p>
Let $N(p,q)$ be the minimal value of $n$ such that $C(p,q,n) \ge 2011$.
</p>
<p>
Find $\displaystyle \sum N(p,q) \,\, \text{ for } p+q \le 2011$.
</p> | https://projecteuler.net/problem=318 | 709313889 |
319 | Let $x_1, x_2, \dots, x_n$ be a sequence of length $n$ such that:
- $x_1 = 2$
- for all $1 \lt i \le n$: $x_{i - 1} \lt x_i$
- for all $i$ and $j$ with $1 \le i, j \le n$: $(x_i)^j \lt (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$.
Find $t(10^{10})$ and give your answer modulo $10^9$. | <p>
Let $x_1, x_2, \dots, x_n$ be a sequence of length $n$ such that:
</p><ul><li>$x_1 = 2$</li>
<li>for all $1 \lt i \le n$: $x_{i - 1} \lt x_i$</li>
<li>for all $i$ and $j$ with $1 \le i, j \le n$: $(x_i)^j \lt (x_j + 1)^i$.</li>
</ul><p>
There are only five such sequences of length $2$, namely:
$\{2,4\}$, $\{2,5\}$, $\{2,6\}$, $\{2,7\}$ and $\{2,8\}$.<br>
There are $293$ such sequences of length $5$; three examples are given below:<br>
$\{2,5,11,25,55\}$, $\{2,6,14,36,88\}$, $\{2,8,22,64,181\}$.
</p>
<p>
Let $t(n)$ denote the number of such sequences of length $n$.<br>
You are given that $t(10) = 86195$ and $t(20) = 5227991891$.
</p>
<p>
Find $t(10^{10})$ and give your answer modulo $10^9$.
</p> | https://projecteuler.net/problem=319 | 268457129 |
320 | Let $N(i)$ be the smallest integer $n$ such that $n!$ is divisible by $(i!)^{1234567890}$
Let $S(u)=\sum N(i)$ for $10 \le i \le u$.
$S(1000)=614538266565663$.
Find $S(1\,000\,000) \bmod 10^{18}$. | <p>
Let $N(i)$ be the smallest integer $n$ such that $n!$ is divisible by $(i!)^{1234567890}$</p>
<p>
Let $S(u)=\sum N(i)$ for $10 \le i \le u$.
</p>
<p>
$S(1000)=614538266565663$.
</p>
<p>
Find $S(1\,000\,000) \bmod 10^{18}$.
</p> | https://projecteuler.net/problem=320 | 278157919195482643 |
321 | A horizontal row comprising of $2n + 1$ squares has $n$ red counters placed at one end and $n$ blue counters at the other end, being separated by a single empty square in the centre. For example, when $n = 3$.
A counter can move from one square to the next (slide) or can jump over another counter (hop) as long as the square next to that counter is unoccupied.
Let $M(n)$ represent the minimum number of moves/actions to completely reverse the positions of the coloured counters; that is, move all the red counters to the right and all the blue counters to the left.
It can be verified $M(3) = 15$, which also happens to be a triangle number.
If we create a sequence based on the values of $n$ for which $M(n)$ is a triangle number then the first five terms would be:
$1$, $3$, $10$, $22$, and $63$, and their sum would be $99$.
Find the sum of the first forty terms of this sequence. | <p>A horizontal row comprising of $2n + 1$ squares has $n$ red counters placed at one end and $n$ blue counters at the other end, being separated by a single empty square in the centre. For example, when $n = 3$.</p>
<p></p><div align="center"><img src="resources/images/0321_swapping_counters_1.gif?1678992056" alt="0321_swapping_counters_1.gif"></div>
<p>A counter can move from one square to the next (slide) or can jump over another counter (hop) as long as the square next to that counter is unoccupied.</p>
<p></p><div align="center"><img src="resources/images/0321_swapping_counters_2.gif?1678992056" alt="0321_swapping_counters_2.gif"></div>
<p>Let $M(n)$ represent the minimum number of moves/actions to completely reverse the positions of the coloured counters; that is, move all the red counters to the right and all the blue counters to the left.</p>
<p>It can be verified $M(3) = 15$, which also happens to be a triangle number.</p>
<p>If we create a sequence based on the values of $n$ for which $M(n)$ is a triangle number then the first five terms would be:
<br>$1$, $3$, $10$, $22$, and $63$, and their sum would be $99$.</p>
<p>Find the sum of the first forty terms of this sequence.</p> | https://projecteuler.net/problem=321 | 2470433131948040 |
322 | Let $T(m, n)$ be the number of the binomial coefficients $^iC_n$ that are divisible by $10$ for $n \le i \lt m$ ($i$, $m$ and $n$ are positive integers).
You are given that $T(10^9, 10^7-10) = 989697000$.
Find $T(10^{18}, 10^{12}-10)$. | <p>
Let $T(m, n)$ be the number of the binomial coefficients $^iC_n$ that are divisible by $10$ for $n \le i \lt m$ ($i$, $m$ and $n$ are positive integers).<br>
You are given that $T(10^9, 10^7-10) = 989697000$.
</p>
<p>
Find $T(10^{18}, 10^{12}-10)$.
</p> | https://projecteuler.net/problem=322 | 999998760323313995 |
323 | Let $y_0, y_1, y_2, \dots$ be a sequence of random unsigned $32$-bit integers
(i.e. $0 \le y_i \lt 2^{32}$, every value equally likely).
For the sequence $x_i$ the following recursion is given:
- $x_0 = 0$ and
- $x_i = x_{i - 1} \boldsymbol \mid y_{i - 1}$, for $i \gt 0$. ($\boldsymbol \mid$ is the bitwise-OR operator).
It can be seen that eventually there will be an index $N$ such that $x_i = 2^{32} - 1$ (a bit-pattern of all ones) for all $i \ge N$.
Find the expected value of $N$.
Give your answer rounded to $10$ digits after the decimal point. | <p>Let $y_0, y_1, y_2, \dots$ be a sequence of random unsigned $32$-bit integers<br>
(i.e. $0 \le y_i \lt 2^{32}$, every value equally likely).</p>
<p>For the sequence $x_i$ the following recursion is given:<br></p><ul><li>$x_0 = 0$ and</li>
<li>$x_i = x_{i - 1} \boldsymbol \mid y_{i - 1}$, for $i \gt 0$. ($\boldsymbol \mid$ is the bitwise-OR operator).</li>
</ul><p>It can be seen that eventually there will be an index $N$ such that $x_i = 2^{32} - 1$ (a bit-pattern of all ones) for all $i \ge N$.</p>
<p>Find the expected value of $N$. <br>
Give your answer rounded to $10$ digits after the decimal point.</p> | https://projecteuler.net/problem=323 | 6.3551758451 |
324 | Let $f(n)$ represent the number of ways one can fill a $3 \times 3 \times n$ tower with blocks of $2 \times 1 \times 1$.
You're allowed to rotate the blocks in any way you like; however, rotations, reflections etc of the tower itself are counted as distinct.
For example (with $q = 100000007$):
$f(2) = 229$,
$f(4) = 117805$,
$f(10) \bmod q = 96149360$,
$f(10^3) \bmod q = 24806056$,
$f(10^6) \bmod q = 30808124$.
Find $f(10^{10000}) \bmod 100000007$. | <p>Let $f(n)$ represent the number of ways one can fill a $3 \times 3 \times n$ tower with blocks of $2 \times 1 \times 1$.<br>You're allowed to rotate the blocks in any way you like; however, rotations, reflections etc of the tower itself are counted as distinct.</p>
<p>For example (with $q = 100000007$):<br>$f(2) = 229$,<br>$f(4) = 117805$,<br>$f(10) \bmod q = 96149360$,<br>$f(10^3) \bmod q = 24806056$,<br>$f(10^6) \bmod q = 30808124$.</p>
<p>Find $f(10^{10000}) \bmod 100000007$.</p> | https://projecteuler.net/problem=324 | 96972774 |
325 | A game is played with two piles of stones and two players.
On each player's turn, the player may remove a number of stones from the larger pile.
The number of stones removed must be a positive multiple of the number of stones in the smaller pile.
E.g. Let the ordered pair $(6,14)$ describe a configuration with $6$ stones in the smaller pile and $14$ stones in the larger pile, then the first player can remove $6$ or $12$ stones from the larger pile.
The player taking all the stones from a pile wins the game.
A winning configuration is one where the first player can force a win. For example, $(1,5)$, $(2,6)$, and $(3,12)$ are winning configurations because the first player can immediately remove all stones in the second pile.
A losing configuration is one where the second player can force a win, no matter what the first player does. For example, $(2,3)$ and $(3,4)$ are losing configurations: any legal move leaves a winning configuration for the second player.
Define $S(N)$ as the sum of $(x_i + y_i)$ for all losing configurations $(x_i, y_i), 0 \lt x_i \lt y_i \le N$.
We can verify that $S(10) = 211$ and $S(10^4) = 230312207313$.
Find $S(10^{16}) \bmod 7^{10}$. | <p>A game is played with two piles of stones and two players.<br>
On each player's turn, the player may remove a number of stones from the larger pile.<br>
The number of stones removed must be a positive multiple of the number of stones in the smaller pile.</p>
<p>E.g. Let the ordered pair $(6,14)$ describe a configuration with $6$ stones in the smaller pile and $14$ stones in the larger pile, then the first player can remove $6$ or $12$ stones from the larger pile.</p>
<p>The player taking all the stones from a pile wins the game.</p>
<p>A <dfn>winning configuration</dfn> is one where the first player can force a win. For example, $(1,5)$, $(2,6)$, and $(3,12)$ are winning configurations because the first player can immediately remove all stones in the second pile.</p>
<p>A <dfn>losing configuration</dfn> is one where the second player can force a win, no matter what the first player does. For example, $(2,3)$ and $(3,4)$ are losing configurations: any legal move leaves a winning configuration for the second player.</p>
<p>Define $S(N)$ as the sum of $(x_i + y_i)$ for all losing configurations $(x_i, y_i), 0 \lt x_i \lt y_i \le N$.<br>
We can verify that $S(10) = 211$ and $S(10^4) = 230312207313$.</p>
<p>Find $S(10^{16}) \bmod 7^{10}$.</p> | https://projecteuler.net/problem=325 | 54672965 |
326 | Let $a_n$ be a sequence recursively defined by:$\quad a_1=1,\quad\displaystyle a_n=\biggl(\sum_{k=1}^{n-1}k\cdot a_k\biggr)\bmod n$.
So the first $10$ elements of $a_n$ are: $1,1,0,3,0,3,5,4,1,9$.
Let $f(N, M)$ represent the number of pairs $(p, q)$ such that:
$$
\def\htmltext#1{\style{font-family:inherit;}{\text{#1}}}
1\le p\le q\le N \quad\htmltext{and}\quad\biggl(\sum_{i=p}^qa_i\biggr)\bmod M=0
$$
It can be seen that $f(10,10)=4$ with the pairs $(3,3)$, $(5,5)$, $(7,9)$ and $(9,10)$.
You are also given that $f(10^4,10^3)=97158$.
Find $f(10^{12},10^6)$. | <p>
Let $a_n$ be a sequence recursively defined by:$\quad a_1=1,\quad\displaystyle a_n=\biggl(\sum_{k=1}^{n-1}k\cdot a_k\biggr)\bmod n$.
</p>
<p>
So the first $10$ elements of $a_n$ are: $1,1,0,3,0,3,5,4,1,9$.
</p>
<p>Let $f(N, M)$ represent the number of pairs $(p, q)$ such that: </p>
<p>
$$
\def\htmltext#1{\style{font-family:inherit;}{\text{#1}}}
1\le p\le q\le N \quad\htmltext{and}\quad\biggl(\sum_{i=p}^qa_i\biggr)\bmod M=0
$$
</p>
<p>
It can be seen that $f(10,10)=4$ with the pairs $(3,3)$, $(5,5)$, $(7,9)$ and $(9,10)$.
</p>
<p>
You are also given that $f(10^4,10^3)=97158$.</p>
<p>
Find $f(10^{12},10^6)$.
</p> | https://projecteuler.net/problem=326 | 1966666166408794329 |
327 | A series of three rooms are connected to each other by automatic doors.
Each door is operated by a security card. Once you enter a room the door automatically closes and that security card cannot be used again. A machine at the start will dispense an unlimited number of cards, but each room (including the starting room) contains scanners and if they detect that you are holding more than three security cards or if they detect an unattended security card on the floor, then all the doors will become permanently locked. However, each room contains a box where you may safely store any number of security cards for use at a later stage.
If you simply tried to travel through the rooms one at a time then as you entered room 3 you would have used all three cards and would be trapped in that room forever!
However, if you make use of the storage boxes, then escape is possible. For example, you could enter room 1 using your first card, place one card in the storage box, and use your third card to exit the room back to the start. Then after collecting three more cards from the dispensing machine you could use one to enter room 1 and collect the card you placed in the box a moment ago. You now have three cards again and will be able to travel through the remaining three doors. This method allows you to travel through all three rooms using six security cards in total.
It is possible to travel through six rooms using a total of $123$ security cards while carrying a maximum of $3$ cards.
Let $C$ be the maximum number of cards which can be carried at any time.
Let $R$ be the number of rooms to travel through.
Let $M(C,R)$ be the minimum number of cards required from the dispensing machine to travel through $R$ rooms carrying up to a maximum of $C$ cards at any time.
For example, $M(3,6)=123$ and $M(4,6)=23$.
And, $\sum M(C, 6) = 146$ for $3 \le C \le 4$.
You are given that $\sum M(C,10)=10382$ for $3 \le C \le 10$.
Find $\sum M(C,30)$ for $3 \le C \le 40$. | <p>A series of three rooms are connected to each other by automatic doors.</p>
<div align="center"><img src="resources/images/0327_rooms_of_doom.gif?1678992056" alt="0327_rooms_of_doom.gif"></div>
<p>Each door is operated by a security card. Once you enter a room the door automatically closes and that security card cannot be used again. A machine at the start will dispense an unlimited number of cards, but each room (including the starting room) contains scanners and if they detect that you are holding more than three security cards or if they detect an unattended security card on the floor, then all the doors will become permanently locked. However, each room contains a box where you may safely store any number of security cards for use at a later stage.</p>
<p>If you simply tried to travel through the rooms one at a time then as you entered room 3 you would have used all three cards and would be trapped in that room forever!</p>
<p>However, if you make use of the storage boxes, then escape is possible. For example, you could enter room 1 using your first card, place one card in the storage box, and use your third card to exit the room back to the start. Then after collecting three more cards from the dispensing machine you could use one to enter room 1 and collect the card you placed in the box a moment ago. You now have three cards again and will be able to travel through the remaining three doors. This method allows you to travel through all three rooms using six security cards in total.</p>
<p>It is possible to travel through six rooms using a total of $123$ security cards while carrying a maximum of $3$ cards.</p>
<p>Let $C$ be the maximum number of cards which can be carried at any time.</p>
<p>Let $R$ be the number of rooms to travel through.</p>
<p>Let $M(C,R)$ be the minimum number of cards required from the dispensing machine to travel through $R$ rooms carrying up to a maximum of $C$ cards at any time.</p>
<p>For example, $M(3,6)=123$ and $M(4,6)=23$.<br>And, $\sum M(C, 6) = 146$ for $3 \le C \le 4$.</p>
<p>You are given that $\sum M(C,10)=10382$ for $3 \le C \le 10$.</p>
<p>Find $\sum M(C,30)$ for $3 \le C \le 40$.</p> | https://projecteuler.net/problem=327 | 34315549139516 |
328 | We are trying to find a hidden number selected from the set of integers $\{1, 2, \dots, n\}$ by asking questions.
Each number (question) we ask, has a cost equal to the number asked and we get one of three possible answers:
- "Your guess is lower than the hidden number", or
- "Yes, that's it!", or
- "Your guess is higher than the hidden number".
Given the value of $n$, an optimal strategy minimizes the total cost (i.e. the sum of all the questions asked) for the worst possible case. E.g.
If $n=3$, the best we can do is obviously to ask the number "2". The answer will immediately lead us to find the hidden number (at a total cost $= 2$).
If $n=8$, we might decide to use a "binary search" type of strategy: Our first question would be "$\mathbf 4$" and if the hidden number is higher than $4$ we will need one or two additional questions.
Let our second question be "$\mathbf 6$". If the hidden number is still higher than $6$, we will need a third question in order to discriminate between $7$ and $8$.
Thus, our third question will be "$\mathbf 7$" and the total cost for this worst-case scenario will be $4+6+7={\color{red}\mathbf{17}}$.
We can improve considerably the worst-case cost for $n=8$, by asking "$\mathbf 5$" as our first question.
If we are told that the hidden number is higher than $5$, our second question will be "$\mathbf 7$", then we'll know for certain what the hidden number is (for a total cost of $5+7={\color{blue}\mathbf{12}}$).
If we are told that the hidden number is lower than $5$, our second question will be "$\mathbf 3$" and if the hidden number is lower than $3$ our third question will be "$\mathbf 1$", giving a total cost of $5+3+1={\color{blue}\mathbf 9}$.
Since ${\color{blue}\mathbf{12}} \gt {\color{blue}\mathbf 9}$, the worst-case cost for this strategy is ${\color{red}\mathbf{12}}$. That's better than what we achieved previously with the "binary search" strategy; it is also better than or equal to any other strategy.
So, in fact, we have just described an optimal strategy for $n=8$.
Let $C(n)$ be the worst-case cost achieved by an optimal strategy for $n$, as described above.
Thus $C(1) = 0$, $C(2) = 1$, $C(3) = 2$ and $C(8) = 12$.
Similarly, $C(100) = 400$ and $\sum \limits_{n = 1}^{100} C(n) = 17575$.
Find $\sum \limits_{n = 1}^{200000} C(n)$. | <p>We are trying to find a hidden number selected from the set of integers $\{1, 2, \dots, n\}$ by asking questions.
Each number (question) we ask, has a <u>cost equal to the number asked</u> and we get one of three possible answers:<br></p><ul><li> "Your guess is lower than the hidden number", or</li>
<li> "Yes, that's it!", or</li>
<li> "Your guess is higher than the hidden number".</li>
</ul><p>Given the value of $n$, an <dfn>optimal strategy</dfn> minimizes the total cost (i.e. the sum of all the questions asked) <u>for the worst possible case</u>. E.g.</p>
<p>If $n=3$, the best we can do is obviously to ask the number "<b>2</b>". The answer will immediately lead us to find the hidden number (at a total cost $= 2$).</p>
<p>If $n=8$, we might decide to use a "binary search" type of strategy: Our first question would be "$\mathbf 4$" and if the hidden number is higher than $4$ we will need one or two additional questions.<br>
Let our second question be "$\mathbf 6$". If the hidden number is still higher than $6$, we will need a third question in order to discriminate between $7$ and $8$.<br>
Thus, our third question will be "$\mathbf 7$" and the total cost for this worst-case scenario will be $4+6+7={\color{red}\mathbf{17}}$.</p>
<p>We can improve considerably the worst-case cost for $n=8$, by asking "$\mathbf 5$" as our first question.<br>
If we are told that the hidden number is higher than $5$, our second question will be "$\mathbf 7$", then we'll know for certain what the hidden number is (for a total cost of $5+7={\color{blue}\mathbf{12}}$).<br>
If we are told that the hidden number is lower than $5$, our second question will be "$\mathbf 3$" and if the hidden number is lower than $3$ our third question will be "$\mathbf 1$", giving a total cost of $5+3+1={\color{blue}\mathbf 9}$.<br>
Since ${\color{blue}\mathbf{12}} \gt {\color{blue}\mathbf 9}$, the worst-case cost for this strategy is ${\color{red}\mathbf{12}}$. That's better than what we achieved previously with the "binary search" strategy; it is also better than or equal to any other strategy.<br>
So, in fact, we have just described an optimal strategy for $n=8$.</p>
<p>Let $C(n)$ be the worst-case cost achieved by an optimal strategy for $n$, as described above.<br>
Thus $C(1) = 0$, $C(2) = 1$, $C(3) = 2$ and $C(8) = 12$.<br>
Similarly, $C(100) = 400$ and $\sum \limits_{n = 1}^{100} C(n) = 17575$.</p>
<p>Find $\sum \limits_{n = 1}^{200000} C(n)$.</p> | https://projecteuler.net/problem=328 | 260511850222 |
329 | Susan has a prime frog.
Her frog is jumping around over $500$ squares numbered $1$ to $500$.
He can only jump one square to the left or to the right, with equal probability, and he cannot jump outside the range $[1;500]$.
(if it lands at either end, it automatically jumps to the only available square on the next move.)
When he is on a square with a prime number on it, he croaks 'P' (PRIME) with probability $2/3$ or 'N' (NOT PRIME) with probability $1/3$ just before jumping to the next square.
When he is on a square with a number on it that is not a prime he croaks 'P' with probability $1/3$ or 'N' with probability $2/3$ just before jumping to the next square.
Given that the frog's starting position is random with the same probability for every square, and given that she listens to his first $15$ croaks, what is the probability that she hears the sequence PPPPNNPPPNPPNPN?
Give your answer as a fraction $p/q$ in reduced form. | <p>Susan has a prime frog.<br>
Her frog is jumping around over $500$ squares numbered $1$ to $500$.
He can only jump one square to the left or to the right, with equal probability, and he cannot jump outside the range $[1;500]$.<br>(if it lands at either end, it automatically jumps to the only available square on the next move.)
</p>
<p>
When he is on a square with a prime number on it, he croaks 'P' (PRIME) with probability $2/3$ or 'N' (NOT PRIME) with probability $1/3$ just before jumping to the next square.<br>
When he is on a square with a number on it that is not a prime he croaks 'P' with probability $1/3$ or 'N' with probability $2/3$ just before jumping to the next square.
</p>
<p>
Given that the frog's starting position is random with the same probability for every square, and given that she listens to his first $15$ croaks, what is the probability that she hears the sequence PPPPNNPPPNPPNPN?
</p>
Give your answer as a fraction $p/q$ in reduced form. | https://projecteuler.net/problem=329 | 199740353/29386561536000 |
330 | An infinite sequence of real numbers $a(n)$ is defined for all integers $n$ as follows:
$$a(n) = \begin{cases}
1 & n \lt 0\\
\sum \limits_{i = 1}^{\infty}{\dfrac{a(n - i)}{i!}} & n \ge 0
\end{cases}$$
For example,
$a(0) = \dfrac{1}{1!} + \dfrac{1}{2!} + \dfrac{1}{3!} + \cdots = e - 1$
$a(1) = \dfrac{e - 1}{1!} + \dfrac{1}{2!} + \dfrac{1}{3!} + \cdots = 2e - 3$
$a(2) = \dfrac{2e - 3}{1!} + \dfrac{e - 1}{2!} + \dfrac{1}{3!} + \cdots = \dfrac{7}{2}e - 6$
with $e = 2.7182818...$ being Euler's constant.
It can be shown that $a(n)$ is of the form $\dfrac{A(n)e + B(n)}{n!}$ for integers $A(n)$ and $B(n)$.
For example, $a(10) = \dfrac{328161643e - 652694486}{10!}$.
Find $A(10^9) + B(10^9)$ and give your answer mod $77\,777\,777$. | An infinite sequence of real numbers $a(n)$ is defined for all integers $n$ as follows:
$$a(n) = \begin{cases}
1 & n \lt 0\\
\sum \limits_{i = 1}^{\infty}{\dfrac{a(n - i)}{i!}} & n \ge 0
\end{cases}$$
<p>For example,<br></p>
<p>$a(0) = \dfrac{1}{1!} + \dfrac{1}{2!} + \dfrac{1}{3!} + \cdots = e - 1$<br>
$a(1) = \dfrac{e - 1}{1!} + \dfrac{1}{2!} + \dfrac{1}{3!} + \cdots = 2e - 3$<br>
$a(2) = \dfrac{2e - 3}{1!} + \dfrac{e - 1}{2!} + \dfrac{1}{3!} + \cdots = \dfrac{7}{2}e - 6$</p>
<p>with $e = 2.7182818...$ being Euler's constant.</p>
<p>It can be shown that $a(n)$ is of the form $\dfrac{A(n)e + B(n)}{n!}$ for integers $A(n)$ and $B(n)$.</p>
<p>For example, $a(10) = \dfrac{328161643e - 652694486}{10!}$.</p>
<p>Find $A(10^9) + B(10^9)$ and give your answer mod $77\,777\,777$.</p> | https://projecteuler.net/problem=330 | 15955822 |
331 | $N \times N$ disks are placed on a square game board. Each disk has a black side and white side.
At each turn, you may choose a disk and flip all the disks in the same row and the same column as this disk: thus $2 \times N - 1$ disks are flipped. The game ends when all disks show their white side. The following example shows a game on a $5 \times 5$ board.
It can be proven that $3$ is the minimal number of turns to finish this game.
The bottom left disk on the $N \times N$ board has coordinates $(0,0)$;
the bottom right disk has coordinates $(N-1,0)$ and the top left disk has coordinates $(0,N-1)$.
Let $C_N$ be the following configuration of a board with $N \times N$ disks:
A disk at $(x, y)$ satisfying $N - 1 \le \sqrt{x^2 + y^2} \lt N$, shows its black side; otherwise, it shows its white side. $C_5$ is shown above.
Let $T(N)$ be the minimal number of turns to finish a game starting from configuration $C_N$ or $0$ if configuration $C_N$ is unsolvable.
We have shown that $T(5)=3$. You are also given that $T(10)=29$ and $T(1\,000)=395253$.
Find $\sum \limits_{i = 3}^{31} T(2^i - i)$. | <p>$N \times N$ disks are placed on a square game board. Each disk has a black side and white side.</p>
<p>At each turn, you may choose a disk and flip all the disks in the same row and the same column as this disk: thus $2 \times N - 1$ disks are flipped. The game ends when all disks show their white side. The following example shows a game on a $5 \times 5$ board.</p>
<div align="center"><img src="resources/images/0331_crossflips3.gif?1678992056" alt="0331_crossflips3.gif"></div>
<p>It can be proven that $3$ is the minimal number of turns to finish this game.</p>
<p>The bottom left disk on the $N \times N$ board has coordinates $(0,0)$;<br>
the bottom right disk has coordinates $(N-1,0)$ and the top left disk has coordinates $(0,N-1)$. </p>
<p>Let $C_N$ be the following configuration of a board with $N \times N$ disks:<br>
A disk at $(x, y)$ satisfying $N - 1 \le \sqrt{x^2 + y^2} \lt N$, shows its black side; otherwise, it shows its white side. $C_5$ is shown above.</p>
<p>Let $T(N)$ be the minimal number of turns to finish a game starting from configuration $C_N$ or $0$ if configuration $C_N$ is unsolvable.<br>
We have shown that $T(5)=3$. You are also given that $T(10)=29$ and $T(1\,000)=395253$.</p>
<p>Find $\sum \limits_{i = 3}^{31} T(2^i - i)$.</p> | https://projecteuler.net/problem=331 | 467178235146843549 |
332 | A spherical triangle is a figure formed on the surface of a sphere by three great circular arcs intersecting pairwise in three vertices.
Let $C(r)$ be the sphere with the centre $(0,0,0)$ and radius $r$.
Let $Z(r)$ be the set of points on the surface of $C(r)$ with integer coordinates.
Let $T(r)$ be the set of spherical triangles with vertices in $Z(r)$.
Degenerate spherical triangles, formed by three points on the same great arc, are not included in $T(r)$.
Let $A(r)$ be the area of the smallest spherical triangle in $T(r)$.
For example $A(14)$ is $3.294040$ rounded to six decimal places.
Find $\sum \limits_{r = 1}^{50} A(r)$. Give your answer rounded to six decimal places. | <p>A <strong>spherical triangle</strong> is a figure formed on the surface of a sphere by three <strong>great circular arcs</strong> intersecting pairwise in three vertices.</p>
<div align="center"><img src="resources/images/0332_spherical.jpg?1678992054" class="dark_img" alt="0332_spherical.jpg"></div>
<p>Let $C(r)$ be the sphere with the centre $(0,0,0)$ and radius $r$.<br>
Let $Z(r)$ be the set of points on the surface of $C(r)$ with integer coordinates.<br>
Let $T(r)$ be the set of spherical triangles with vertices in $Z(r)$.
Degenerate spherical triangles, formed by three points on the same great arc, are <u>not</u> included in $T(r)$.<br>
Let $A(r)$ be the area of the smallest spherical triangle in $T(r)$.</p>
<p>For example $A(14)$ is $3.294040$ rounded to six decimal places.</p>
<p>Find $\sum \limits_{r = 1}^{50} A(r)$. Give your answer rounded to six decimal places.</p> | https://projecteuler.net/problem=332 | 2717.751525 |
333 | All positive integers can be partitioned in such a way that each and every term of the partition can be expressed as $2^i \times 3^j$, where $i,j \ge 0$.
Let's consider only such partitions where none of the terms can divide any of the other terms.
For example, the partition of $17 = 2 + 6 + 9 = (2^1 \times 3^0 + 2^1 \times 3^1 + 2^0 \times 3^2)$ would not be valid since $2$ can divide $6$. Neither would the partition $17 = 16 + 1 = (2^4 \times 3^0 + 2^0 \times 3^0)$ since $1$ can divide $16$. The only valid partition of $17$ would be $8 + 9 = (2^3 \times 3^0 + 2^0 \times 3^2)$.
Many integers have more than one valid partition, the first being $11$ having the following two partitions.
$11 = 2 + 9 = (2^1 \times 3^0 + 2^0 \times 3^2)$
$11 = 8 + 3 = (2^3 \times 3^0 + 2^0 \times 3^1)$
Let's define $P(n)$ as the number of valid partitions of $n$. For example, $P(11) = 2$.
Let's consider only the prime integers $q$ which would have a single valid partition such as $P(17)$.
The sum of the primes $q \lt 100$ such that $P(q)=1$ equals $233$.
Find the sum of the primes $q \lt 1000000$ such that $P(q)=1$. | <p>All positive integers can be partitioned in such a way that each and every term of the partition can be expressed as $2^i \times 3^j$, where $i,j \ge 0$.</p>
<p>Let's consider only such partitions where none of the terms can divide any of the other terms.
<br>For example, the partition of $17 = 2 + 6 + 9 = (2^1 \times 3^0 + 2^1 \times 3^1 + 2^0 \times 3^2)$ would not be valid since $2$ can divide $6$. Neither would the partition $17 = 16 + 1 = (2^4 \times 3^0 + 2^0 \times 3^0)$ since $1$ can divide $16$. The only valid partition of $17$ would be $8 + 9 = (2^3 \times 3^0 + 2^0 \times 3^2)$.</p>
<p>Many integers have more than one valid partition, the first being $11$ having the following two partitions.
<br>$11 = 2 + 9 = (2^1 \times 3^0 + 2^0 \times 3^2)$
<br>$11 = 8 + 3 = (2^3 \times 3^0 + 2^0 \times 3^1)$</p>
<p>Let's define $P(n)$ as the number of valid partitions of $n$. For example, $P(11) = 2$.</p>
<p>Let's consider only the prime integers $q$ which would have a single valid partition such as $P(17)$.</p>
<p>The sum of the primes $q \lt 100$ such that $P(q)=1$ equals $233$.</p>
<p>Find the sum of the primes $q \lt 1000000$ such that $P(q)=1$.</p> | https://projecteuler.net/problem=333 | 3053105 |
334 | In Plato's heaven, there exist an infinite number of bowls in a straight line.
Each bowl either contains some or none of a finite number of beans.
A child plays a game, which allows only one kind of move: removing two beans from any bowl, and putting one in each of the two adjacent bowls.
The game ends when each bowl contains either one or no beans.
For example, consider two adjacent bowls containing $2$ and $3$ beans respectively, all other bowls being empty. The following eight moves will finish the game:
You are given the following sequences:
$\def\htmltext#1{\style{font-family:inherit;}{\text{#1}}}$
$
\begin{align}
\qquad t_0 &= 123456,\cr
\qquad t_i &= \cases{
\;\;\frac{t_{i-1}}{2},&$\htmltext{if }t_{i-1}\htmltext{ is even}$\cr
\left\lfloor\frac{t_{i-1}}{2}\right\rfloor\oplus 926252,&$\htmltext{if }t_{i-1}\htmltext{ is odd}$\cr}\cr
&\qquad\htmltext{where }\lfloor x\rfloor\htmltext{ is the floor function }\cr
&\qquad\!\htmltext{and }\oplus\htmltext{is the bitwise XOR operator.}\cr
\qquad b_i &= (t_i\bmod2^{11}) + 1.\cr
\end{align}
$
The first two terms of the last sequence are $b_1 = 289$ and $b_2 = 145$.
If we start with $b_1$ and $b_2$ beans in two adjacent bowls, $3419100$ moves would be required to finish the game.
Consider now $1500$ adjacent bowls containing $b_1, b_2, \ldots, b_{1500}$ beans respectively, all other bowls being empty. Find how many moves it takes before the game ends. | <p>In Plato's heaven, there exist an infinite number of bowls in a straight line.<br>
Each bowl either contains some or none of a finite number of beans.<br>
A child plays a game, which allows only one kind of move: removing two beans from any bowl, and putting one in each of the two adjacent bowls.<br> The game ends when each bowl contains either one or no beans.</p>
<p>For example, consider two adjacent bowls containing $2$ and $3$ beans respectively, all other bowls being empty. The following eight moves will finish the game:</p>
<div align="center"><img src="resources/images/0334_beans.gif?1678992056" class="dark_img" alt="0334_beans.gif"></div>
<p>You are given the following sequences:<br></p>
<p>
$\def\htmltext#1{\style{font-family:inherit;}{\text{#1}}}$
$
\begin{align}
\qquad t_0 &= 123456,\cr
\qquad t_i &= \cases{
\;\;\frac{t_{i-1}}{2},&$\htmltext{if }t_{i-1}\htmltext{ is even}$\cr
\left\lfloor\frac{t_{i-1}}{2}\right\rfloor\oplus 926252,&$\htmltext{if }t_{i-1}\htmltext{ is odd}$\cr}\cr
&\qquad\htmltext{where }\lfloor x\rfloor\htmltext{ is the floor function }\cr
&\qquad\!\htmltext{and }\oplus\htmltext{is the bitwise XOR operator.}\cr
\qquad b_i &= (t_i\bmod2^{11}) + 1.\cr
\end{align}
$
</p>
<p>The first two terms of the last sequence are $b_1 = 289$ and $b_2 = 145$.<br>
If we start with $b_1$ and $b_2$ beans in two adjacent bowls, $3419100$ moves would be required to finish the game.</p>
<p>Consider now $1500$ adjacent bowls containing $b_1, b_2, \ldots, b_{1500}$ beans respectively, all other bowls being empty. Find how many moves it takes before the game ends.</p> | https://projecteuler.net/problem=334 | 150320021261690835 |
335 | Whenever Peter feels bored, he places some bowls, containing one bean each, in a circle. After this, he takes all the beans out of a certain bowl and drops them one by one in the bowls going clockwise. He repeats this, starting from the bowl he dropped the last bean in, until the initial situation appears again. For example with 5 bowls he acts as follows:
So with $5$ bowls it takes Peter $15$ moves to return to the initial situation.
Let $M(x)$ represent the number of moves required to return to the initial situation, starting with $x$ bowls. Thus, $M(5) = 15$. It can also be verified that $M(100) = 10920$.
Find $\displaystyle \sum_{k=0}^{10^{18}} M(2^k + 1)$. Give your answer modulo $7^9$. | <p>Whenever Peter feels bored, he places some bowls, containing one bean each, in a circle. After this, he takes all the beans out of a certain bowl and drops them one by one in the bowls going clockwise. He repeats this, starting from the bowl he dropped the last bean in, until the initial situation appears again. For example with 5 bowls he acts as follows:</p>
<div align="center"><img src="resources/images/0335_mancala.gif?1678992056" class="dark_img" alt="0335_mancala.gif"></div>
<p>So with $5$ bowls it takes Peter $15$ moves to return to the initial situation.</p>
<p>Let $M(x)$ represent the number of moves required to return to the initial situation, starting with $x$ bowls. Thus, $M(5) = 15$. It can also be verified that $M(100) = 10920$.</p>
<p>Find $\displaystyle \sum_{k=0}^{10^{18}} M(2^k + 1)$. Give your answer modulo $7^9$.</p> | https://projecteuler.net/problem=335 | 5032316 |
336 | A train is used to transport four carriages in the order: ABCD. However, sometimes when the train arrives to collect the carriages they are not in the correct order.
To rearrange the carriages they are all shunted on to a large rotating turntable. After the carriages are uncoupled at a specific point the train moves off the turntable pulling the carriages still attached with it. The remaining carriages are rotated 180 degrees. All of the carriages are then rejoined and this process is repeated as often as necessary in order to obtain the least number of uses of the turntable.
Some arrangements, such as ADCB, can be solved easily: the carriages are separated between A and D, and after DCB are rotated the correct order has been achieved.
However, Simple Simon, the train driver, is not known for his efficiency, so he always solves the problem by initially getting carriage A in the correct place, then carriage B, and so on.
Using four carriages, the worst possible arrangements for Simon, which we shall call maximix arrangements, are DACB and DBAC; each requiring him five rotations (although, using the most efficient approach, they could be solved using just three rotations). The process he uses for DACB is shown below.
It can be verified that there are 24 maximix arrangements for six carriages, of which the tenth lexicographic maximix arrangement is DFAECB.
Find the 2011th lexicographic maximix arrangement for eleven carriages. | <p>A train is used to transport four carriages in the order: ABCD. However, sometimes when the train arrives to collect the carriages they are not in the correct order. <br>
To rearrange the carriages they are all shunted on to a large rotating turntable. After the carriages are uncoupled at a specific point the train moves off the turntable pulling the carriages still attached with it. The remaining carriages are rotated 180 degrees. All of the carriages are then rejoined and this process is repeated as often as necessary in order to obtain the least number of uses of the turntable.<br>
Some arrangements, such as ADCB, can be solved easily: the carriages are separated between A and D, and after DCB are rotated the correct order has been achieved.</p>
<p>However, Simple Simon, the train driver, is not known for his efficiency, so he always solves the problem by initially getting carriage A in the correct place, then carriage B, and so on.</p>
<p>Using four carriages, the worst possible arrangements for Simon, which we shall call <i>maximix arrangements</i>, are DACB and DBAC; each requiring him five rotations (although, using the most efficient approach, they could be solved using just three rotations). The process he uses for DACB is shown below.</p>
<div align="center"><img src="resources/images/0336_maximix.gif?1678992056" class="dark_img" alt="0336_maximix.gif"></div>
<p>It can be verified that there are 24 maximix arrangements for six carriages, of which the tenth lexicographic maximix arrangement is DFAECB.</p>
<p>Find the 2011<sup>th</sup> lexicographic maximix arrangement for eleven carriages.</p> | https://projecteuler.net/problem=336 | CAGBIHEFJDK |
337 | Let $\{a_1, a_2, \dots, a_n\}$ be an integer sequence of length $n$ such that:
- $a_1 = 6$
- for all $1 \le i \lt n$: $\phi(a_i) \lt \phi(a_{i + 1}) \lt a_i \lt a_{i + 1}$.1
Let $S(N)$ be the number of such sequences with $a_n \le N$.
For example, $S(10) = 4$: $\{6\}$, $\{6, 8\}$, $\{6, 8, 9\}$ and $\{6, 10\}$.
We can verify that $S(100) = 482073668$ and $S(10\,000) \bmod 10^8 = 73808307$.
Find $S(20\,000\,000) \bmod 10^8$.
1 $\phi$ denotes Euler's totient function. | <p>Let $\{a_1, a_2, \dots, a_n\}$ be an integer sequence of length $n$ such that:</p>
<ul><li>$a_1 = 6$</li>
<li>for all $1 \le i \lt n$: $\phi(a_i) \lt \phi(a_{i + 1}) \lt a_i \lt a_{i + 1}$.<sup>1</sup></li>
</ul><p>Let $S(N)$ be the number of such sequences with $a_n \le N$.<br>
For example, $S(10) = 4$: $\{6\}$, $\{6, 8\}$, $\{6, 8, 9\}$ and $\{6, 10\}$.<br>
We can verify that $S(100) = 482073668$ and $S(10\,000) \bmod 10^8 = 73808307$.</p>
<p>Find $S(20\,000\,000) \bmod 10^8$.</p>
<p><sup>1</sup> $\phi$ denotes <strong>Euler's totient function</strong>.</p> | https://projecteuler.net/problem=337 | 85068035 |
338 | A rectangular sheet of grid paper with integer dimensions $w \times h$ is given. Its grid spacing is $1$.
When we cut the sheet along the grid lines into two pieces and rearrange those pieces without overlap, we can make new rectangles with different dimensions.
For example, from a sheet with dimensions $9 \times 4$, we can make rectangles with dimensions $18 \times 2$, $12 \times 3$ and $6 \times 6$ by cutting and rearranging as below:
Similarly, from a sheet with dimensions $9 \times 8$, we can make rectangles with dimensions $18 \times 4$ and $12 \times 6$.
For a pair $w$ and $h$, let $F(w, h)$ be the number of distinct rectangles that can be made from a sheet with dimensions $w \times h$.
For example, $F(2,1) = 0$, $F(2,2) = 1$, $F(9,4) = 3$ and $F(9,8) = 2$.
Note that rectangles congruent to the initial one are not counted in $F(w, h)$.
Note also that rectangles with dimensions $w \times h$ and dimensions $h \times w$ are not considered distinct.
For an integer $N$, let $G(N)$ be the sum of $F(w, h)$ for all pairs $w$ and $h$ which satisfy $0 \lt h \le w \le N$.
We can verify that $G(10) = 55$, $G(10^3) = 971745$ and $G(10^5) = 9992617687$.
Find $G(10^{12})$. Give your answer modulo $10^8$. | <p>A rectangular sheet of grid paper with integer dimensions $w \times h$ is given. Its grid spacing is $1$.<br>
When we cut the sheet along the grid lines into two pieces and rearrange those pieces without overlap, we can make new rectangles with different dimensions.</p>
<p>For example, from a sheet with dimensions $9 \times 4$, we can make rectangles with dimensions $18 \times 2$, $12 \times 3$ and $6 \times 6$ by cutting and rearranging as below:</p>
<div align="center">
<img src="resources/images/0338_gridpaper.gif?1678992056" alt="0338_gridpaper.gif"><br></div>
<p>Similarly, from a sheet with dimensions $9 \times 8$, we can make rectangles with dimensions $18 \times 4$ and $12 \times 6$.</p>
<p>For a pair $w$ and $h$, let $F(w, h)$ be the number of distinct rectangles that can be made from a sheet with dimensions $w \times h$.<br>
For example, $F(2,1) = 0$, $F(2,2) = 1$, $F(9,4) = 3$ and $F(9,8) = 2$. <br>
Note that rectangles congruent to the initial one are not counted in $F(w, h)$.<br>
Note also that rectangles with dimensions $w \times h$ and dimensions $h \times w$ are not considered distinct.</p>
<p>For an integer $N$, let $G(N)$ be the sum of $F(w, h)$ for all pairs $w$ and $h$ which satisfy $0 \lt h \le w \le N$.<br>
We can verify that $G(10) = 55$, $G(10^3) = 971745$ and $G(10^5) = 9992617687$.</p>
<p>Find $G(10^{12})$. Give your answer modulo $10^8$.</p> | https://projecteuler.net/problem=338 | 15614292 |
339 | "And he came towards a valley, through which ran a river; and the borders of the valley were wooded, and on each side of the river were level meadows. And on one side of the river he saw a flock of white sheep, and on the other a flock of black sheep. And whenever one of the white sheep bleated, one of the black sheep would cross over and become white; and when one of the black sheep bleated, one of the white sheep would cross over and become black."
en.wikisource.org
Initially each flock consists of $n$ sheep. Each sheep (regardless of colour) is equally likely to be the next sheep to bleat. After a sheep has bleated and a sheep from the other flock has crossed over, Peredur may remove a number of white sheep in order to maximize the expected final number of black sheep. Let $E(n)$ be the expected final number of black sheep if Peredur uses an optimal strategy.
You are given that $E(5) = 6.871346$ rounded to $6$ places behind the decimal point.
Find $E(10\,000)$ and give your answer rounded to $6$ places behind the decimal point. | <p>
<i>"And he came towards a valley, through which ran a river; and the borders of the valley were wooded, and on each side of the river were level meadows. And on one side of the river he saw a flock of white sheep, and on the other a flock of black sheep. And whenever one of the white sheep bleated, one of the black sheep would cross over and become white; and when one of the black sheep bleated, one of the white sheep would cross over and become black."</i><br><a href="http://en.wikisource.org/wiki/The_Mabinogion/Peredur_the_Son_of_Evrawc">en.wikisource.org</a>
</p>
<p>
Initially each flock consists of $n$ sheep. Each sheep (regardless of colour) is equally likely to be the next sheep to bleat. After a sheep has bleated and a sheep from the other flock has crossed over, Peredur may remove a number of white sheep in order to maximize the expected final number of black sheep. Let $E(n)$ be the expected final number of black sheep if Peredur uses an optimal strategy.
</p>
<p>
You are given that $E(5) = 6.871346$ rounded to $6$ places behind the decimal point.<br>
Find $E(10\,000)$ and give your answer rounded to $6$ places behind the decimal point.
</p> | https://projecteuler.net/problem=339 | 19823.542204 |
340 | For fixed integers $a, b, c$, define the crazy function $F(n)$ as follows:
$F(n) = n - c$ for all $n \gt b$
$F(n) = F(a + F(a + F(a + F(a + n))))$ for all $n \le b$.
Also, define $S(a, b, c) = \sum \limits_{n = 0}^b F(n)$.
For example, if $a = 50$, $b = 2000$ and $c = 40$, then $F(0) = 3240$ and $F(2000) = 2040$.
Also, $S(50, 2000, 40) = 5204240$.
Find the last $9$ digits of $S(21^7, 7^{21}, 12^7)$. | <p>
For fixed integers $a, b, c$, define the <dfn>crazy function</dfn> $F(n)$ as follows:<br>
$F(n) = n - c$ for all $n \gt b$<br>
$F(n) = F(a + F(a + F(a + F(a + n))))$ for all $n \le b$.
</p>
<p>Also, define $S(a, b, c) = \sum \limits_{n = 0}^b F(n)$.</p>
<p>
For example, if $a = 50$, $b = 2000$ and $c = 40$, then $F(0) = 3240$ and $F(2000) = 2040$.<br>
Also, $S(50, 2000, 40) = 5204240$.
</p>
<p>
Find the last $9$ digits of $S(21^7, 7^{21}, 12^7)$.
</p> | https://projecteuler.net/problem=340 | 291504964 |
341 | The Golomb's self-describing sequence $(G(n))$ is the only nondecreasing sequence of natural numbers such that $n$ appears exactly $G(n)$ times in the sequence. The values of $G(n)$ for the first few $n$ are
$$
\begin{matrix}
n & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & \ldots \\
G(n) & 1 & 2 & 2 & 3 & 3 & 4 & 4 & 4 & 5 & 5 & 5 & 6 & 6 & 6 & 6 & \ldots
\end{matrix}
$$
You are given that $G(10^3) = 86$, $G(10^6) = 6137$.
You are also given that $\sum G(n^3) = 153506976$ for $1 \le n \lt 10^3$.
Find $\sum G(n^3)$ for $1 \le n \lt 10^6$. | <p>The <b>Golomb's self-describing sequence</b> $(G(n))$ is the only nondecreasing sequence of natural numbers such that $n$ appears exactly $G(n)$ times in the sequence. The values of $G(n)$ for the first few $n$ are</p>
<p></p><div align="center">
$$
\begin{matrix}
n & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & \ldots \\
G(n) & 1 & 2 & 2 & 3 & 3 & 4 & 4 & 4 & 5 & 5 & 5 & 6 & 6 & 6 & 6 & \ldots
\end{matrix}
$$
</div>
<p>You are given that $G(10^3) = 86$, $G(10^6) = 6137$.<br>
You are also given that $\sum G(n^3) = 153506976$ for $1 \le n \lt 10^3$.</p>
<p>Find $\sum G(n^3)$ for $1 \le n \lt 10^6$.</p> | https://projecteuler.net/problem=341 | 56098610614277014 |
342 | Consider the number $50$.
$50^2 = 2500 = 2^2 \times 5^4$, so $\phi(2500) = 2 \times 4 \times 5^3 = 8 \times 5^3 = 2^3 \times 5^3$. 1
So $2500$ is a square and $\phi(2500)$ is a cube.
Find the sum of all numbers $n$, $1 \lt n \lt 10^{10}$ such that $\phi(n^2)$ is a cube.
1 $\phi$ denotes Euler's totient function. | <p>
Consider the number $50$.<br>
$50^2 = 2500 = 2^2 \times 5^4$, so $\phi(2500) = 2 \times 4 \times 5^3 = 8 \times 5^3 = 2^3 \times 5^3$. <sup>1</sup><br>
So $2500$ is a square and $\phi(2500)$ is a cube.
</p>
<p>
Find the sum of all numbers $n$, $1 \lt n \lt 10^{10}$ such that $\phi(n^2)$ is a cube.
</p>
<p>
<sup>1</sup> $\phi$ denotes <strong>Euler's totient function</strong>.
</p> | https://projecteuler.net/problem=342 | 5943040885644 |
343 | For any positive integer $k$, a finite sequence $a_i$ of fractions $x_i/y_i$ is defined by:
$a_1 = 1/k$ and
$a_i = (x_{i - 1} + 1) / (y_{i - 1} - 1)$ reduced to lowest terms for $i \gt 1$.
When $a_i$ reaches some integer $n$, the sequence stops. (That is, when $y_i = 1$.)
Define $f(k) = n$.
For example, for $k = 20$:
$1/20 \to 2/19 \to 3/18 = 1/6 \to 2/5 \to 3/4 \to 4/3 \to 5/2 \to 6/1 = 6$
So $f(20) = 6$.
Also $f(1) = 1$, $f(2) = 2$, $f(3) = 1$ and $\sum f(k^3) = 118937$ for $1 \le k \le 100$.
Find $\sum f(k^3)$ for $1 \le k \le 2 \times 10^6$. | <p>For any positive integer $k$, a finite sequence $a_i$ of fractions $x_i/y_i$ is defined by:<br>
$a_1 = 1/k$ and<br>
$a_i = (x_{i - 1} + 1) / (y_{i - 1} - 1)$ reduced to lowest terms for $i \gt 1$.<br>
When $a_i$ reaches some integer $n$, the sequence stops. (That is, when $y_i = 1$.)<br>
Define $f(k) = n$. <br>
For example, for $k = 20$:
</p>
<p>
$1/20 \to 2/19 \to 3/18 = 1/6 \to 2/5 \to 3/4 \to 4/3 \to 5/2 \to 6/1 = 6$
</p>
<p>
So $f(20) = 6$.
</p>
<p>
Also $f(1) = 1$, $f(2) = 2$, $f(3) = 1$ and $\sum f(k^3) = 118937$ for $1 \le k \le 100$.
</p>
<p>
Find $\sum f(k^3)$ for $1 \le k \le 2 \times 10^6$.
</p> | https://projecteuler.net/problem=343 | 269533451410884183 |
344 | One variant of N.G. de Bruijn's silver dollar game can be described as follows:
On a strip of squares a number of coins are placed, at most one coin per square. Only one coin, called the silver dollar, has any value. Two players take turns making moves. At each turn a player must make either a regular or a special move.
A regular move consists of selecting one coin and moving it one or more squares to the left. The coin cannot move out of the strip or jump on or over another coin.
Alternatively, the player can choose to make the special move of pocketing the leftmost coin rather than making a regular move. If no regular moves are possible, the player is forced to pocket the leftmost coin.
The winner is the player who pockets the silver dollar.
A winning configuration is an arrangement of coins on the strip where the first player can force a win no matter what the second player does.
Let $W(n,c)$ be the number of winning configurations for a strip of $n$ squares, $c$ worthless coins and one silver dollar.
You are given that $W(10,2) = 324$ and $W(100,10) = 1514704946113500$.
Find $W(1\,000\,000, 100)$ modulo the semiprime $1000\,036\,000\,099$ ($= 1\,000\,003 \cdot 1\,000\,033$). | <p>One variant of N.G. de Bruijn's <strong>silver dollar</strong> game can be described as follows:</p>
<p>On a strip of squares a number of coins are placed, at most one coin per square. Only one coin, called the <strong>silver dollar</strong>, has any value. Two players take turns making moves. At each turn a player must make either a <dfn>regular</dfn> or a <dfn>special</dfn> move.</p>
<p>A <dfn>regular</dfn> move consists of selecting one coin and moving it one or more squares to the left. The coin cannot move out of the strip or jump on or over another coin.</p>
<p>Alternatively, the player can choose to make the <dfn>special</dfn> move of pocketing the leftmost coin rather than making a regular move. If no regular moves are possible, the player is forced to pocket the leftmost coin.</p>
<p>The winner is the player who pockets the silver dollar.</p>
<div align="center">
<img src="resources/images/0344_silverdollar.gif?1678992056" alt="0344_silverdollar.gif"><br></div>
<p>A <dfn>winning configuration</dfn> is an arrangement of coins on the strip where the first player can force a win no matter what the second player does.</p>
<p>Let $W(n,c)$ be the number of winning configurations for a strip of $n$ squares, $c$ worthless coins and one silver dollar.</p>
<p>You are given that $W(10,2) = 324$ and $W(100,10) = 1514704946113500$.</p>
<p>Find $W(1\,000\,000, 100)$ modulo the semiprime $1000\,036\,000\,099$ ($= 1\,000\,003 \cdot 1\,000\,033$).
</p> | https://projecteuler.net/problem=344 | 65579304332 |
345 | We define the Matrix Sum of a matrix as the maximum possible sum of matrix elements such that none of the selected elements share the same row or column.
For example, the Matrix Sum of the matrix below equals 3315 ( = 863 + 383 + 343 + 959 + 767):
7 53 183 439 863
497 383 563 79 973
287 63 343 169 583
627 343 773 959 943
767 473 103 699 303
Find the Matrix Sum of:
7 53 183 439 863 497 383 563 79 973 287 63 343 169 583
627 343 773 959 943 767 473 103 699 303 957 703 583 639 913
447 283 463 29 23 487 463 993 119 883 327 493 423 159 743
217 623 3 399 853 407 103 983 89 463 290 516 212 462 350
960 376 682 962 300 780 486 502 912 800 250 346 172 812 350
870 456 192 162 593 473 915 45 989 873 823 965 425 329 803
973 965 905 919 133 673 665 235 509 613 673 815 165 992 326
322 148 972 962 286 255 941 541 265 323 925 281 601 95 973
445 721 11 525 473 65 511 164 138 672 18 428 154 448 848
414 456 310 312 798 104 566 520 302 248 694 976 430 392 198
184 829 373 181 631 101 969 613 840 740 778 458 284 760 390
821 461 843 513 17 901 711 993 293 157 274 94 192 156 574
34 124 4 878 450 476 712 914 838 669 875 299 823 329 699
815 559 813 459 522 788 168 586 966 232 308 833 251 631 107
813 883 451 509 615 77 281 613 459 205 380 274 302 35 805 | <p>We define the <dfn>Matrix Sum</dfn> of a matrix as the maximum possible sum of matrix elements such that none of the selected elements share the same row or column.</p>
<p>For example, the Matrix Sum of the matrix below equals 3315 ( = 863 + 383 + 343 + 959 + 767):</p>
<p style="text-align:center;font-family:'courier new';">
7 53 183 439 <span style="color:#00ff00;font-family:'courier new';"><b>863</b></span><br>
497 <span style="color:#00ff00;font-family:'courier new';"><b>383</b></span> 563 79 973<br>
287 63 <span style="color:#00ff00;font-family:'courier new';"><b>343</b></span> 169 583<br>
627 343 773 <span style="color:#00ff00;font-family:'courier new';"><b>959</b></span> 943<br><span style="color:#00ff00;font-family:'courier new';"><b>767</b></span> 473 103 699 303<br></p>
<p>
Find the Matrix Sum of:<br></p>
<p style="text-align:center;font-family:'courier new';">
7 53 183 439 863 497 383 563 79 973 287 63 343 169 583<br>
627 343 773 959 943 767 473 103 699 303 957 703 583 639 913<br>
447 283 463 29 23 487 463 993 119 883 327 493 423 159 743<br>
217 623 3 399 853 407 103 983 89 463 290 516 212 462 350<br>
960 376 682 962 300 780 486 502 912 800 250 346 172 812 350<br>
870 456 192 162 593 473 915 45 989 873 823 965 425 329 803<br>
973 965 905 919 133 673 665 235 509 613 673 815 165 992 326<br>
322 148 972 962 286 255 941 541 265 323 925 281 601 95 973<br>
445 721 11 525 473 65 511 164 138 672 18 428 154 448 848<br>
414 456 310 312 798 104 566 520 302 248 694 976 430 392 198<br>
184 829 373 181 631 101 969 613 840 740 778 458 284 760 390<br>
821 461 843 513 17 901 711 993 293 157 274 94 192 156 574<br>
34 124 4 878 450 476 712 914 838 669 875 299 823 329 699<br>
815 559 813 459 522 788 168 586 966 232 308 833 251 631 107<br>
813 883 451 509 615 77 281 613 459 205 380 274 302 35 805<br></p> | https://projecteuler.net/problem=345 | 13938 |
346 | The number $7$ is special, because $7$ is $111$ written in base $2$, and $11$ written in base $6$ (i.e. $7_{10} = 11_6 = 111_2$). In other words, $7$ is a repunit in at least two bases $b \gt 1$.
We shall call a positive integer with this property a strong repunit. It can be verified that there are $8$ strong repunits below $50$: $\{1,7,13,15,21,31,40,43\}$.
Furthermore, the sum of all strong repunits below $1000$ equals $15864$.
Find the sum of all strong repunits below $10^{12}$. | <p>
The number $7$ is special, because $7$ is $111$ written in base $2$, and $11$ written in base $6$ (i.e. $7_{10} = 11_6 = 111_2$). In other words, $7$ is a repunit in at least two bases $b \gt 1$.
</p>
<p>
We shall call a positive integer with this property a strong repunit. It can be verified that there are $8$ strong repunits below $50$: $\{1,7,13,15,21,31,40,43\}$.<br>
Furthermore, the sum of all strong repunits below $1000$ equals $15864$.
</p>
Find the sum of all strong repunits below $10^{12}$. | https://projecteuler.net/problem=346 | 336108797689259276 |
347 | The largest integer $\le 100$ that is only divisible by both the primes $2$ and $3$ is $96$, as $96=32\times 3=2^5 \times 3$.
For two distinct primes $p$ and $q$ let $M(p,q,N)$ be the largest positive integer $\le N$ only divisible by both $p$ and $q$ and $M(p,q,N)=0$ if such a positive integer does not exist.
E.g. $M(2,3,100)=96$.
$M(3,5,100)=75$ and not $90$ because $90$ is divisible by $2$, $3$ and $5$.
Also $M(2,73,100)=0$ because there does not exist a positive integer $\le 100$ that is divisible by both $2$ and $73$.
Let $S(N)$ be the sum of all distinct $M(p,q,N)$.
$S(100)=2262$.
Find $S(10\,000\,000)$. | <p>
The largest integer $\le 100$ that is only divisible by both the primes $2$ and $3$ is $96$, as $96=32\times 3=2^5 \times 3$.
For two <i>distinct</i> primes $p$ and $q$ let $M(p,q,N)$ be the largest positive integer $\le N$ only divisible by both $p$ and $q$ and $M(p,q,N)=0$ if such a positive integer does not exist.
</p>
<p>
E.g. $M(2,3,100)=96$.<br>
$M(3,5,100)=75$ and not $90$ because $90$ is divisible by $2$, $3$ and $5$.<br>
Also $M(2,73,100)=0$ because there does not exist a positive integer $\le 100$ that is divisible by both $2$ and $73$.
</p>
<p>
Let $S(N)$ be the sum of all distinct $M(p,q,N)$.
$S(100)=2262$.
</p>
<p>
Find $S(10\,000\,000)$.
</p> | https://projecteuler.net/problem=347 | 11109800204052 |
348 | Many numbers can be expressed as the sum of a square and a cube. Some of them in more than one way.
Consider the palindromic numbers that can be expressed as the sum of a square and a cube, both greater than $1$, in exactly $4$ different ways.
For example, $5229225$ is a palindromic number and it can be expressed in exactly $4$ different ways:
$2285^2 + 20^3$
$2223^2 + 66^3$
$1810^2 + 125^3$
$1197^2 + 156^3$
Find the sum of the five smallest such palindromic numbers. | <p>Many numbers can be expressed as the sum of a square and a cube. Some of them in more than one way.</p>
<p>Consider the palindromic numbers that can be expressed as the sum of a square and a cube, both greater than $1$, in <b>exactly</b> $4$ different ways.<br>
For example, $5229225$ is a palindromic number and it can be expressed in exactly $4$ different ways:</p>
<p>$2285^2 + 20^3$<br>
$2223^2 + 66^3$<br>
$1810^2 + 125^3$<br>
$1197^2 + 156^3$</p>
<p>Find the sum of the five smallest such palindromic numbers.</p> | https://projecteuler.net/problem=348 | 1004195061 |
349 | An ant moves on a regular grid of squares that are coloured either black or white.
The ant is always oriented in one of the cardinal directions (left, right, up or down) and moves from square to adjacent square according to the following rules:
- if it is on a black square, it flips the colour of the square to white, rotates $90$ degrees counterclockwise and moves forward one square.
- if it is on a white square, it flips the colour of the square to black, rotates $90$ degrees clockwise and moves forward one square.
Starting with a grid that is entirely white, how many squares are black after $10^{18}$ moves of the ant? | <p>
An ant moves on a regular grid of squares that are coloured either black or white.<br>
The ant is always oriented in one of the cardinal directions (left, right, up or down) and moves from square to adjacent square according to the following rules:<br>
- if it is on a black square, it flips the colour of the square to white, rotates $90$ degrees counterclockwise and moves forward one square.<br>
- if it is on a white square, it flips the colour of the square to black, rotates $90$ degrees clockwise and moves forward one square.<br></p>
<p>
Starting with a grid that is entirely white, how many squares are black after $10^{18}$ moves of the ant?
</p> | https://projecteuler.net/problem=349 | 115384615384614952 |
350 | A list of size $n$ is a sequence of $n$ natural numbers.
Examples are $(2,4,6)$, $(2,6,4)$, $(10,6,15,6)$, and $(11)$.
The greatest common divisor, or $\gcd$, of a list is the largest natural number that divides all entries of the list.
Examples: $\gcd(2,6,4) = 2$, $\gcd(10,6,15,6) = 1$ and $\gcd(11) = 11$.
The least common multiple, or $\operatorname{lcm}$, of a list is the smallest natural number divisible by each entry of the list.
Examples: $\operatorname{lcm}(2,6,4) = 12$, $\operatorname{lcm}(10,6,15,6) = 30$ and $\operatorname{lcm}(11) = 11$.
Let $f(G, L, N)$ be the number of lists of size $N$ with $\gcd \ge G$ and $\operatorname{lcm} \le L$. For example:
$f(10, 100, 1) = 91$.
$f(10, 100, 2) = 327$.
$f(10, 100, 3) = 1135$.
$f(10, 100, 1000) \bmod 101^4 = 3286053$.
Find $f(10^6, 10^{12}, 10^{18}) \bmod 101^4$. | <p>A <dfn>list of size $n$</dfn> is a sequence of $n$ natural numbers.<br> Examples are $(2,4,6)$, $(2,6,4)$, $(10,6,15,6)$, and $(11)$.
</p><p>
The <strong>greatest common divisor</strong>, or $\gcd$, of a list is the largest natural number that divides all entries of the list. <br>Examples: $\gcd(2,6,4) = 2$, $\gcd(10,6,15,6) = 1$ and $\gcd(11) = 11$.
</p><p>
The <strong>least common multiple</strong>, or $\operatorname{lcm}$, of a list is the smallest natural number divisible by each entry of the list. <br>Examples: $\operatorname{lcm}(2,6,4) = 12$, $\operatorname{lcm}(10,6,15,6) = 30$ and $\operatorname{lcm}(11) = 11$.
</p><p>
Let $f(G, L, N)$ be the number of lists of size $N$ with $\gcd \ge G$ and $\operatorname{lcm} \le L$. For example:
</p><p>
$f(10, 100, 1) = 91$.<br>
$f(10, 100, 2) = 327$.<br>
$f(10, 100, 3) = 1135$.<br>
$f(10, 100, 1000) \bmod 101^4 = 3286053$.
</p><p>
Find $f(10^6, 10^{12}, 10^{18}) \bmod 101^4$.
</p> | https://projecteuler.net/problem=350 | 84664213 |
351 | A hexagonal orchard of order $n$ is a triangular lattice made up of points within a regular hexagon with side $n$. The following is an example of a hexagonal orchard of order $5$:
Highlighted in green are the points which are hidden from the center by a point closer to it. It can be seen that for a hexagonal orchard of order $5$, $30$ points are hidden from the center.
Let $H(n)$ be the number of points hidden from the center in a hexagonal orchard of order $n$.
$H(5) = 30$. $H(10) = 138$. $H(1\,000) = 1177848$.
Find $H(100\,000\,000)$. | <p>A <dfn>hexagonal orchard</dfn> of order $n$ is a triangular lattice made up of points within a regular hexagon with side $n$. The following is an example of a hexagonal orchard of order $5$:
</p>
<div align="center">
<img src="resources/images/0351_hexorchard.png?1678992052" class="dark_img" alt="0351_hexorchard.png"><br></div>
<p>
Highlighted in green are the points which are hidden from the center by a point closer to it. It can be seen that for a hexagonal orchard of order $5$, $30$ points are hidden from the center.
</p>
<p>
Let $H(n)$ be the number of points hidden from the center in a hexagonal orchard of order $n$.
</p>
<p>
$H(5) = 30$. $H(10) = 138$. $H(1\,000) = 1177848$.
</p>
<p>
Find $H(100\,000\,000)$.
</p> | https://projecteuler.net/problem=351 | 11762187201804552 |
352 | Each one of the $25$ sheep in a flock must be tested for a rare virus, known to affect $2\%$ of the sheep population.
An accurate and extremely sensitive PCR test exists for blood samples, producing a clear positive / negative result, but it is very time-consuming and expensive.
Because of the high cost, the vet-in-charge suggests that instead of performing $25$ separate tests, the following procedure can be used instead:
The sheep are split into $5$ groups of $5$ sheep in each group.
For each group, the $5$ samples are mixed together and a single test is performed. Then,
- If the result is negative, all the sheep in that group are deemed to be virus-free.
- If the result is positive, $5$ additional tests will be performed (a separate test for each animal) to determine the affected individual(s).
Since the probability of infection for any specific animal is only $0.02$, the first test (on the pooled samples) for each group will be:
- Negative (and no more tests needed) with probability $0.98^5 = 0.9039207968$.
- Positive ($5$ additional tests needed) with probability $1 - 0.9039207968 = 0.0960792032$.
Thus, the expected number of tests for each group is $1 + 0.0960792032 \times 5 = 1.480396016$.
Consequently, all $5$ groups can be screened using an average of only $1.480396016 \times 5 = \mathbf{7.40198008}$ tests, which represents a huge saving of more than $70\%$!
Although the scheme we have just described seems to be very efficient, it can still be improved considerably (always assuming that the test is sufficiently sensitive and that there are no adverse effects caused by mixing different samples). E.g.:
- We may start by running a test on a mixture of all the $25$ samples. It can be verified that in about $60.35\%$ of the cases this test will be negative, thus no more tests will be needed. Further testing will only be required for the remaining $39.65\%$ of the cases.
- If we know that at least one animal in a group of $5$ is infected and the first $4$ individual tests come out negative, there is no need to run a test on the fifth animal (we know that it must be infected).
- We can try a different number of groups / different number of animals in each group, adjusting those numbers at each level so that the total expected number of tests will be minimised.
To simplify the very wide range of possibilities, there is one restriction we place when devising the most cost-efficient testing scheme: whenever we start with a mixed sample, all the sheep contributing to that sample must be fully screened (i.e. a verdict of infected / virus-free must be reached for all of them) before we start examining any other animals.
For the current example, it turns out that the most cost-efficient testing scheme (we'll call it the optimal strategy) requires an average of just $\mathbf{4.155452}$ tests!
Using the optimal strategy, let $T(s,p)$ represent the average number of tests needed to screen a flock of $s$ sheep for a virus having probability $p$ to be present in any individual.
Thus, rounded to six decimal places, $T(25, 0.02) = 4.155452$ and $T(25, 0.10) = 12.702124$.
Find $\sum T(10000, p)$ for $p=0.01, 0.02, 0.03, \dots 0.50$.
Give your answer rounded to six decimal places. | <p>
Each one of the $25$ sheep in a flock must be tested for a rare virus, known to affect $2\%$ of the sheep population.
An accurate and extremely sensitive PCR test exists for blood samples, producing a clear positive / negative result, but it is very time-consuming and expensive.
</p>
<p>
Because of the high cost, the vet-in-charge suggests that instead of performing $25$ separate tests, the following procedure can be used instead:<br><br>
The sheep are split into $5$ groups of $5$ sheep in each group.
For each group, the $5$ samples are mixed together and a single test is performed. Then,
</p><ul><li>If the result is negative, all the sheep in that group are deemed to be virus-free.</li>
<li>If the result is positive, $5$ additional tests will be performed (a separate test for each animal) to determine the affected individual(s).</li>
</ul><p>
Since the probability of infection for any specific animal is only $0.02$, the first test (on the pooled samples) for each group will be:
</p><ul><li>Negative (and no more tests needed) with probability $0.98^5 = 0.9039207968$.</li>
<li>Positive ($5$ additional tests needed) with probability $1 - 0.9039207968 = 0.0960792032$.</li>
</ul><p>
Thus, the expected number of tests for each group is $1 + 0.0960792032 \times 5 = 1.480396016$.<br>
Consequently, all $5$ groups can be screened using an average of only $1.480396016 \times 5 = \mathbf{7.40198008}$ tests, which represents a huge saving of more than $70\%$!
</p>
<p>
Although the scheme we have just described seems to be very efficient, it can still be improved considerably (always assuming that the test is sufficiently sensitive and that there are no adverse effects caused by mixing different samples). E.g.:
</p><ul><li>We may start by running a test on a mixture of all the $25$ samples. It can be verified that in about $60.35\%$ of the cases this test will be negative, thus no more tests will be needed. Further testing will only be required for the remaining $39.65\%$ of the cases.</li>
<li>If we know that at least one animal in a group of $5$ is infected and the first $4$ individual tests come out negative, there is no need to run a test on the fifth animal (we know that it must be infected).</li>
<li>We can try a different number of groups / different number of animals in each group, adjusting those numbers at each level so that the total expected number of tests will be minimised.</li>
</ul><p>
To simplify the very wide range of possibilities, there is one restriction we place when devising the most cost-efficient testing scheme: whenever we start with a mixed sample, all the sheep contributing to that sample must be fully screened (i.e. a verdict of infected / virus-free must be reached for all of them) before we start examining any other animals.
</p>
For the current example, it turns out that the most cost-efficient testing scheme (we'll call it the <dfn>optimal strategy</dfn>) requires an average of just $\mathbf{4.155452}$ tests!
<p>
Using the optimal strategy, let $T(s,p)$ represent the average number of tests needed to screen a flock of $s$ sheep for a virus having probability $p$ to be present in any individual.<br>
Thus, rounded to six decimal places, $T(25, 0.02) = 4.155452$ and $T(25, 0.10) = 12.702124$.
</p>
<p>
Find $\sum T(10000, p)$ for $p=0.01, 0.02, 0.03, \dots 0.50$.<br>
Give your answer rounded to six decimal places.
</p> | https://projecteuler.net/problem=352 | 378563.260589 |
353 | A moon could be described by the sphere $C(r)$ with centre $(0,0,0)$ and radius $r$.
There are stations on the moon at the points on the surface of $C(r)$ with integer coordinates. The station at $(0,0,r)$ is called North Pole station, the station at $(0,0,-r)$ is called South Pole station.
All stations are connected with each other via the shortest road on the great arc through the stations. A journey between two stations is risky. If d is the length of the road between two stations, $\left(\frac{d}{\pi r}\right)^2$ is a measure for the risk of the journey (let us call it the risk of the road). If the journey includes more than two stations, the risk of the journey is the sum of risks of the used roads.
A direct journey from the North Pole station to the South Pole station has the length $\pi r$ and risk $1$. The journey from the North Pole station to the South Pole station via $(0,r,0)$ has the same length, but a smaller risk:
$$
\left(\frac{\frac{1}{2}\pi r}{\pi r}\right)^2+\left(\frac{\frac{1}{2}\pi r}{\pi r}\right)^2=0.5
$$
The minimal risk of a journey from the North Pole station to the South Pole station on $C(r)$ is $M(r)$.
You are given that $M(7)=0.1784943998$ rounded to $10$ digits behind the decimal point.
Find $\displaystyle{\sum_{n=1}^{15}M(2^n-1)}$.
Give your answer rounded to $10$ digits behind the decimal point in the form a.bcdefghijk. | <p>
A moon could be described by the sphere $C(r)$ with centre $(0,0,0)$ and radius $r$.
</p>
<p>
There are stations on the moon at the points on the surface of $C(r)$ with integer coordinates. The station at $(0,0,r)$ is called North Pole station, the station at $(0,0,-r)$ is called South Pole station.
</p>
<p>
All stations are connected with each other via the shortest road on the great arc through the stations. A journey between two stations is risky. If <var>d</var> is the length of the road between two stations, $\left(\frac{d}{\pi r}\right)^2$ is a measure for the risk of the journey (let us call it the risk of the road). If the journey includes more than two stations, the risk of the journey is the sum of risks of the used roads.
</p>
<p>
A direct journey from the North Pole station to the South Pole station has the length $\pi r$ and risk $1$. The journey from the North Pole station to the South Pole station via $(0,r,0)$ has the same length, but a smaller risk:</p>
$$
\left(\frac{\frac{1}{2}\pi r}{\pi r}\right)^2+\left(\frac{\frac{1}{2}\pi r}{\pi r}\right)^2=0.5
$$
<p>
The minimal risk of a journey from the North Pole station to the South Pole station on $C(r)$ is $M(r)$.
</p>
<p>
You are given that $M(7)=0.1784943998$ rounded to $10$ digits behind the decimal point.
</p>
<p>
Find $\displaystyle{\sum_{n=1}^{15}M(2^n-1)}$.
</p>
<p>
Give your answer rounded to $10$ digits behind the decimal point in the form a.bcdefghijk.
</p> | https://projecteuler.net/problem=353 | 1.2759860331 |
354 | Consider a honey bee's honeycomb where each cell is a perfect regular hexagon with side length $1$.
One particular cell is occupied by the queen bee.
For a positive real number $L$, let $\text{B}(L)$ count the cells with distance $L$ from the queen bee cell (all distances are measured from centre to centre); you may assume that the honeycomb is large enough to accommodate for any distance we wish to consider.
For example, $\text{B}(\sqrt 3)=6$, $\text{B}(\sqrt {21}) = 12$ and $\text{B}(111\,111\,111) = 54$.
Find the number of $L \le 5 \times 10^{11}$ such that $\text{B}(L) = 450$. | <p>Consider a honey bee's honeycomb where each cell is a perfect regular hexagon with side length $1$.</p>
<div align="center">
<img src="resources/images/0354_bee_honeycomb.png?1678992052" alt="0354_bee_honeycomb.png"></div>
<p>
One particular cell is occupied by the queen bee.<br>
For a positive real number $L$, let $\text{B}(L)$ count the cells with distance $L$ from the queen bee cell (all distances are measured from centre to centre); you may assume that the honeycomb is large enough to accommodate for any distance we wish to consider. <br>
For example, $\text{B}(\sqrt 3)=6$, $\text{B}(\sqrt {21}) = 12$ and $\text{B}(111\,111\,111) = 54$.</p>
<p>Find the number of $L \le 5 \times 10^{11}$ such that $\text{B}(L) = 450$.</p> | https://projecteuler.net/problem=354 | 58065134 |
355 | Define $\operatorname{Co}(n)$ to be the maximal possible sum of a set of mutually co-prime elements from $\{1,2,\dots,n\}$.
For example $\operatorname{Co}(10)$ is $30$ and hits that maximum on the subset $\{1,5,7,8,9\}$.
You are given that $\operatorname{Co}(30) = 193$ and $\operatorname{Co}(100) = 1356$.
Find $\operatorname{Co}(200000)$. | <p>
Define $\operatorname{Co}(n)$ to be the maximal possible sum of a set of mutually co-prime elements from $\{1,2,\dots,n\}$.<br> For example $\operatorname{Co}(10)$ is $30$ and hits that maximum on the subset $\{1,5,7,8,9\}$.
</p>
<p>
You are given that $\operatorname{Co}(30) = 193$ and $\operatorname{Co}(100) = 1356$.
</p>
<p>Find $\operatorname{Co}(200000)$.
</p> | https://projecteuler.net/problem=355 | 1726545007 |
356 | Let $a_n$ be the largest real root of a polynomial $g(x) = x^3 - 2^n \cdot x^2 + n$.
For example, $a_2 = 3.86619826\cdots$
Find the last eight digits of $\sum \limits_{i = 1}^{30} \lfloor a_i^{987654321} \rfloor$.
Note: $\lfloor a \rfloor$ represents the floor function. | <p>
Let $a_n$ be the largest real root of a polynomial $g(x) = x^3 - 2^n \cdot x^2 + n$.<br>
For example, $a_2 = 3.86619826\cdots$</p>
<p>
Find the last eight digits of $\sum \limits_{i = 1}^{30} \lfloor a_i^{987654321} \rfloor$.</p>
<p>
<u><i>Note</i></u>: $\lfloor a \rfloor$ represents the floor function.</p> | https://projecteuler.net/problem=356 | 28010159 |
357 | Consider the divisors of $30$: $1,2,3,5,6,10,15,30$.
It can be seen that for every divisor $d$ of $30$, $d + 30 / d$ is prime.
Find the sum of all positive integers $n$ not exceeding $100\,000\,000$
such that for every divisor $d$ of $n$, $d + n / d$ is prime. | <p>
Consider the divisors of $30$: $1,2,3,5,6,10,15,30$.<br>
It can be seen that for every divisor $d$ of $30$, $d + 30 / d$ is prime.
</p>
<p>
Find the sum of all positive integers $n$ not exceeding $100\,000\,000$<br>such that for every divisor $d$ of $n$, $d + n / d$ is prime.
</p> | https://projecteuler.net/problem=357 | 1739023853137 |
358 | A cyclic number with $n$ digits has a very interesting property:
When it is multiplied by $1, 2, 3, 4, \dots, n$, all the products have exactly the same digits, in the same order, but rotated in a circular fashion!
The smallest cyclic number is the $6$-digit number $142857$:
$142857 \times 1 = 142857$
$142857 \times 2 = 285714$
$142857 \times 3 = 428571$
$142857 \times 4 = 571428$
$142857 \times 5 = 714285$
$142857 \times 6 = 857142$
The next cyclic number is $0588235294117647$ with $16$ digits :
$0588235294117647 \times 1 = 0588235294117647$
$0588235294117647 \times 2 = 1176470588235294$
$0588235294117647 \times 3 = 1764705882352941$
$\dots$
$0588235294117647 \times 16 = 9411764705882352$
Note that for cyclic numbers, leading zeros are important.
There is only one cyclic number for which, the eleven leftmost digits are $00000000137$ and the five rightmost digits are $56789$ (i.e., it has the form $00000000137 \cdots 56789$ with an unknown number of digits in the middle). Find the sum of all its digits. | <p>A <strong>cyclic number</strong> with $n$ digits has a very interesting property:<br>
When it is multiplied by $1, 2, 3, 4, \dots, n$, all the products have exactly the same digits, in the same order, but rotated in a circular fashion!
</p>
<p>
The smallest cyclic number is the $6$-digit number $142857$:<br>
$142857 \times 1 = 142857$<br>
$142857 \times 2 = 285714$<br>
$142857 \times 3 = 428571$<br>
$142857 \times 4 = 571428$<br>
$142857 \times 5 = 714285$<br>
$142857 \times 6 = 857142$
</p>
<p>
The next cyclic number is $0588235294117647$ with $16$ digits :<br>
$0588235294117647 \times 1 = 0588235294117647$<br>
$0588235294117647 \times 2 = 1176470588235294$<br>
$0588235294117647 \times 3 = 1764705882352941$<br>
$\dots$<br>
$0588235294117647 \times 16 = 9411764705882352$
</p>
<p>
Note that for cyclic numbers, leading zeros are important.
</p>
<p>
There is only one cyclic number for which, the eleven leftmost digits are $00000000137$ and the five rightmost digits are $56789$ (i.e., it has the form $00000000137 \cdots 56789$ with an unknown number of digits in the middle). Find the sum of all its digits.
</p> | https://projecteuler.net/problem=358 | 3284144505 |
359 | An infinite number of people (numbered $1$, $2$, $3$, etc.) are lined up to get a room at Hilbert's newest infinite hotel. The hotel contains an infinite number of floors (numbered $1$, $2$, $3$, etc.), and each floor contains an infinite number of rooms (numbered $1$, $2$, $3$, etc.).
Initially the hotel is empty. Hilbert declares a rule on how the $n$th person is assigned a room: person $n$ gets the first vacant room in the lowest numbered floor satisfying either of the following:
- the floor is empty
- the floor is not empty, and if the latest person taking a room in that floor is person $m$, then $m + n$ is a perfect square
Person $1$ gets room $1$ in floor $1$ since floor $1$ is empty.
Person $2$ does not get room $2$ in floor $1$ since $1 + 2 = 3$ is not a perfect square.
Person $2$ instead gets room $1$ in floor $2$ since floor $2$ is empty.
Person $3$ gets room $2$ in floor $1$ since $1 + 3 = 4$ is a perfect square.
Eventually, every person in the line gets a room in the hotel.
Define $P(f, r)$ to be $n$ if person $n$ occupies room $r$ in floor $f$, and $0$ if no person occupies the room. Here are a few examples:
$P(1, 1) = 1$
$P(1, 2) = 3$
$P(2, 1) = 2$
$P(10, 20) = 440$
$P(25, 75) = 4863$
$P(99, 100) = 19454$
Find the sum of all $P(f, r)$ for all positive $f$ and $r$ such that $f \times r = 71328803586048$ and give the last $8$ digits as your answer. | <p>
An infinite number of people (numbered $1$, $2$, $3$, etc.) are lined up to get a room at Hilbert's newest infinite hotel. The hotel contains an infinite number of floors (numbered $1$, $2$, $3$, etc.), and each floor contains an infinite number of rooms (numbered $1$, $2$, $3$, etc.).
</p>
<p>
Initially the hotel is empty. Hilbert declares a rule on how the $n$<sup>th</sup> person is assigned a room: person $n$ gets the first vacant room in the lowest numbered floor satisfying either of the following:
</p><ul><li>the floor is empty</li>
<li>the floor is not empty, and if the latest person taking a room in that floor is person $m$, then $m + n$ is a perfect square</li>
</ul><p>
Person $1$ gets room $1$ in floor $1$ since floor $1$ is empty.
<br>Person $2$ does not get room $2$ in floor $1$ since $1 + 2 = 3$ is not a perfect square.
<br>Person $2$ instead gets room $1$ in floor $2$ since floor $2$ is empty.
<br>Person $3$ gets room $2$ in floor $1$ since $1 + 3 = 4$ is a perfect square.
</p>
<p>
Eventually, every person in the line gets a room in the hotel.
</p>
<p>
Define $P(f, r)$ to be $n$ if person $n$ occupies room $r$ in floor $f$, and $0$ if no person occupies the room. Here are a few examples:
<br>$P(1, 1) = 1$
<br>$P(1, 2) = 3$
<br>$P(2, 1) = 2$
<br>$P(10, 20) = 440$
<br>$P(25, 75) = 4863$
<br>$P(99, 100) = 19454$
</p>
<p>
Find the sum of all $P(f, r)$ for all positive $f$ and $r$ such that $f \times r = 71328803586048$ and give the last $8$ digits as your answer.
</p> | https://projecteuler.net/problem=359 | 40632119 |
360 | Given two points $(x_1, y_1, z_1)$ and $(x_2, y_2, z_2)$ in three dimensional space, the Manhattan distance between those points is defined as
$|x_1 - x_2| + |y_1 - y_2| + |z_1 - z_2|$.
Let $C(r)$ be a sphere with radius $r$ and center in the origin $O(0,0,0)$.
Let $I(r)$ be the set of all points with integer coordinates on the surface of $C(r)$.
Let $S(r)$ be the sum of the Manhattan distances of all elements of $I(r)$ to the origin $O$.
E.g. $S(45)=34518$.
Find $S(10^{10})$. | <p>
Given two points $(x_1, y_1, z_1)$ and $(x_2, y_2, z_2)$ in three dimensional space, the <strong>Manhattan distance</strong> between those points is defined as<br>$|x_1 - x_2| + |y_1 - y_2| + |z_1 - z_2|$.
</p>
<p>
Let $C(r)$ be a sphere with radius $r$ and center in the origin $O(0,0,0)$.<br>
Let $I(r)$ be the set of all points with integer coordinates on the surface of $C(r)$.<br>
Let $S(r)$ be the sum of the Manhattan distances of all elements of $I(r)$ to the origin $O$.
</p>
<p>
E.g. $S(45)=34518$.
</p>
<p>
Find $S(10^{10})$.
</p> | https://projecteuler.net/problem=360 | 878825614395267072 |
361 | The Thue-Morse sequence $\{T_n\}$ is a binary sequence satisfying:
- $T_0 = 0$
- $T_{2n} = T_n$
- $T_{2n + 1} = 1 - T_n$
The first several terms of $\{T_n\}$ are given as follows:
$01101001{\color{red}10010}1101001011001101001\cdots$
We define $\{A_n\}$ as the sorted sequence of integers such that the binary expression of each element appears as a subsequence in $\{T_n\}$.
For example, the decimal number $18$ is expressed as $10010$ in binary. $10010$ appears in $\{T_n\}$ ($T_8$ to $T_{12}$), so $18$ is an element of $\{A_n\}$.
The decimal number $14$ is expressed as $1110$ in binary. $1110$ never appears in $\{T_n\}$, so $14$ is not an element of $\{A_n\}$.
The first several terms of $\{A_n\}$ are given as follows:
| $n$ | $0$ | $1$ | $2$ | $3$ | $4$ | $5$ | $6$ | $7$ | $8$ | $9$ | $10$ | $11$ | $12$ | $\cdots$ |
| $A_n$ | $0$ | $1$ | $2$ | $3$ | $4$ | $5$ | $6$ | $9$ | $10$ | $11$ | $12$ | $13$ | $18$ | $\cdots$ |
We can also verify that $A_{100} = 3251$ and $A_{1000} = 80852364498$.
Find the last $9$ digits of $\sum \limits_{k = 1}^{18} A_{10^k}$. | <p>The <strong>Thue-Morse sequence</strong> $\{T_n\}$ is a binary sequence satisfying:</p>
<ul><li>$T_0 = 0$</li>
<li>$T_{2n} = T_n$</li>
<li>$T_{2n + 1} = 1 - T_n$</li>
</ul><p>
The first several terms of $\{T_n\}$ are given as follows:<br>
$01101001{\color{red}10010}1101001011001101001\cdots$
</p>
<p>
We define $\{A_n\}$ as the sorted sequence of integers such that the binary expression of each element appears as a subsequence in $\{T_n\}$.<br>
For example, the decimal number $18$ is expressed as $10010$ in binary. $10010$ appears in $\{T_n\}$ ($T_8$ to $T_{12}$), so $18$ is an element of $\{A_n\}$.<br>
The decimal number $14$ is expressed as $1110$ in binary. $1110$ never appears in $\{T_n\}$, so $14$ is not an element of $\{A_n\}$.
</p>
<p>
The first several terms of $\{A_n\}$ are given as follows:</p>
<table align="center"><tr>
<td align="center" width="30">$n$</td>
<td align="right" width="30">$0$</td>
<td align="right" width="30">$1$</td>
<td align="right" width="30">$2$</td>
<td align="right" width="30">$3$</td>
<td align="right" width="30">$4$</td>
<td align="right" width="30">$5$</td>
<td align="right" width="30">$6$</td>
<td align="right" width="30">$7$</td>
<td align="right" width="30">$8$</td>
<td align="right" width="30">$9$</td>
<td align="right" width="30">$10$</td>
<td align="right" width="30">$11$</td>
<td align="right" width="30">$12$</td>
<td align="right" width="30">$\cdots$</td>
</tr><tr>
<td align="center" width="30">$A_n$</td>
<td align="right" width="30">$0$</td>
<td align="right" width="30">$1$</td>
<td align="right" width="30">$2$</td>
<td align="right" width="30">$3$</td>
<td align="right" width="30">$4$</td>
<td align="right" width="30">$5$</td>
<td align="right" width="30">$6$</td>
<td align="right" width="30">$9$</td>
<td align="right" width="30">$10$</td>
<td align="right" width="30">$11$</td>
<td align="right" width="30">$12$</td>
<td align="right" width="30">$13$</td>
<td align="right" width="30">$18$</td>
<td align="right" width="30">$\cdots$</td>
</tr></table>
<p>
We can also verify that $A_{100} = 3251$ and $A_{1000} = 80852364498$.
</p>
<p>
Find the last $9$ digits of $\sum \limits_{k = 1}^{18} A_{10^k}$.
</p> | https://projecteuler.net/problem=361 | 178476944 |
362 | Consider the number $54$.
$54$ can be factored in $7$ distinct ways into one or more factors larger than $1$:
$54$, $2 \times 27$, $3 \times 18$, $6 \times 9$, $3 \times 3 \times 6$, $2 \times 3 \times 9$ and $2 \times 3 \times 3 \times 3$.
If we require that the factors are all squarefree only two ways remain: $3 \times 3 \times 6$ and $2 \times 3 \times 3 \times 3$.
Let's call $\operatorname{Fsf}(n)$ the number of ways $n$ can be factored into one or more squarefree factors larger than $1$, so
$\operatorname{Fsf}(54)=2$.
Let $S(n)$ be $\sum \operatorname{Fsf}(k)$ for $k=2$ to $n$.
$S(100)=193$.
Find $S(10\,000\,000\,000)$. | <p>
Consider the number $54$.<br>
$54$ can be factored in $7$ distinct ways into one or more factors larger than $1$:<br>
$54$, $2 \times 27$, $3 \times 18$, $6 \times 9$, $3 \times 3 \times 6$, $2 \times 3 \times 9$ and $2 \times 3 \times 3 \times 3$.<br>
If we require that the factors are all squarefree only two ways remain: $3 \times 3 \times 6$ and $2 \times 3 \times 3 \times 3$.
</p>
<p>
Let's call $\operatorname{Fsf}(n)$ the number of ways $n$ can be factored into one or more squarefree factors larger than $1$, so
$\operatorname{Fsf}(54)=2$.
</p>
<p>
Let $S(n)$ be $\sum \operatorname{Fsf}(k)$ for $k=2$ to $n$.
</p>
<p>
$S(100)=193$.
</p>
<p>
Find $S(10\,000\,000\,000)$.
</p> | https://projecteuler.net/problem=362 | 457895958010 |
363 | A cubic Bézier curve is defined by four points: $P_0, P_1, P_2,$ and $P_3$.
The curve is constructed as follows:
On the segments $P_0 P_1$, $P_1 P_2$, and $P_2 P_3$ the points $Q_0, Q_1,$ and $Q_2$ are drawn such that $\dfrac{P_0 Q_0}{P_0 P_1} = \dfrac{P_1 Q_1}{P_1 P_2} = \dfrac{P_2 Q_2}{P_2 P_3} = t$, with $t$ in $[0, 1]$.
On the segments $Q_0 Q_1$ and $Q_1 Q_2$ the points $R_0$ and $R_1$ are drawn such that
$\dfrac{Q_0 R_0}{Q_0 Q_1} = \dfrac{Q_1 R_1}{Q_1 Q_2} = t$ for the same value of $t$.
On the segment $R_0 R_1$ the point $B$ is drawn such that $\dfrac{R_0 B}{R_0 R_1} = t$ for the same value of $t$.
The Bézier curve defined by the points $P_0, P_1, P_2, P_3$ is the locus of $B$ as $Q_0$ takes all possible positions on the segment $P_0 P_1$.
(Please note that for all points the value of $t$ is the same.)
From the construction it is clear that the Bézier curve will be tangent to the segments $P_0 P_1$ in $P_0$ and $P_2 P_3$ in $P_3$.
A cubic Bézier curve with $P_0 = (1, 0), P_1 = (1, v), P_2 = (v, 1),$ and $P_3 = (0, 1)$ is used to approximate a quarter circle.
The value $v \gt 0$ is chosen such that the area enclosed by the lines $O P_0, OP_3$ and the curve is equal to $\dfrac{\pi}{4}$ (the area of the quarter circle).
By how many percent does the length of the curve differ from the length of the quarter circle?
That is, if $L$ is the length of the curve, calculate $100 \times \dfrac{L - \frac{\pi}{2}}{\frac{\pi}{2}}$
Give your answer rounded to 10 digits behind the decimal point. | <p>A cubic Bézier curve is defined by four points: $P_0, P_1, P_2,$ and $P_3$.</p>
<div class="float_right"><img src="resources/images/0363_bezier.png?1678992053" class="dark_img" alt="0363_bezier.png"></div>
<p>The curve is constructed as follows:</p>
<p>On the segments $P_0 P_1$, $P_1 P_2$, and $P_2 P_3$ the points $Q_0, Q_1,$ and $Q_2$ are drawn such that $\dfrac{P_0 Q_0}{P_0 P_1} = \dfrac{P_1 Q_1}{P_1 P_2} = \dfrac{P_2 Q_2}{P_2 P_3} = t$, with $t$ in $[0, 1]$.</p>
<p>On the segments $Q_0 Q_1$ and $Q_1 Q_2$ the points $R_0$ and $R_1$ are drawn such that<br>
$\dfrac{Q_0 R_0}{Q_0 Q_1} = \dfrac{Q_1 R_1}{Q_1 Q_2} = t$ for the same value of $t$.</p>
<p>On the segment $R_0 R_1$ the point $B$ is drawn such that $\dfrac{R_0 B}{R_0 R_1} = t$ for the same value of $t$.</p>
<p>The Bézier curve defined by the points $P_0, P_1, P_2, P_3$ is the locus of $B$ as $Q_0$ takes all possible positions on the segment $P_0 P_1$.<br>
(Please note that for all points the value of $t$ is the same.)</p>
<p>From the construction it is clear that the Bézier curve will be tangent to the segments $P_0 P_1$ in $P_0$ and $P_2 P_3$ in $P_3$.</p>
<p>A cubic Bézier curve with $P_0 = (1, 0), P_1 = (1, v), P_2 = (v, 1),$ and $P_3 = (0, 1)$ is used to approximate a quarter circle.<br>
The value $v \gt 0$ is chosen such that the area enclosed by the lines $O P_0, OP_3$ and the curve is equal to $\dfrac{\pi}{4}$ (the area of the quarter circle).</p>
<p>By how many percent does the length of the curve differ from the length of the quarter circle?<br>
That is, if $L$ is the length of the curve, calculate $100 \times \dfrac{L - \frac{\pi}{2}}{\frac{\pi}{2}}$<br>
Give your answer rounded to 10 digits behind the decimal point.</p> | https://projecteuler.net/problem=363 | 0.0000372091 |
364 | There are $N$ seats in a row. $N$ people come after each other to fill the seats according to the following rules:
- If there is any seat whose adjacent seat(s) are not occupied take such a seat.
- If there is no such seat and there is any seat for which only one adjacent seat is occupied take such a seat.
- Otherwise take one of the remaining available seats.
Let $T(N)$ be the number of possibilities that $N$ seats are occupied by $N$ people with the given rules.
The following figure shows $T(4)=8$.
We can verify that $T(10) = 61632$ and $T(1\,000) \bmod 100\,000\,007 = 47255094$.
Find $T(1\,000\,000) \bmod 100\,000\,007$. | <p>
There are $N$ seats in a row. $N$ people come after each other to fill the seats according to the following rules:
</p><ol type="1"><li>If there is any seat whose adjacent seat(s) are not occupied take such a seat.</li>
<li>If there is no such seat and there is any seat for which only one adjacent seat is occupied take such a seat.</li>
<li>Otherwise take one of the remaining available seats. </li>
</ol>
Let $T(N)$ be the number of possibilities that $N$ seats are occupied by $N$ people with the given rules.<br> The following figure shows $T(4)=8$.
<div align="center">
<img src="resources/images/0364_comf_dist.gif?1678992056" class="dark_img" alt="0364_comf_dist.gif"></div>
<p>We can verify that $T(10) = 61632$ and $T(1\,000) \bmod 100\,000\,007 = 47255094$.</p>
<p>Find $T(1\,000\,000) \bmod 100\,000\,007$.</p> | https://projecteuler.net/problem=364 | 44855254 |
365 | The binomial coefficient $\displaystyle{\binom{10^{18}}{10^9}}$ is a number with more than $9$ billion ($9\times 10^9$) digits.
Let $M(n,k,m)$ denote the binomial coefficient $\displaystyle{\binom{n}{k}}$ modulo $m$.
Calculate $\displaystyle{\sum M(10^{18},10^9,p\cdot q\cdot r)}$ for $1000\lt p\lt q\lt r\lt 5000$ and $p$,$q$,$r$ prime. | <p>
The binomial coefficient $\displaystyle{\binom{10^{18}}{10^9}}$ is a number with more than $9$ billion ($9\times 10^9$) digits.
</p>
<p>
Let $M(n,k,m)$ denote the binomial coefficient $\displaystyle{\binom{n}{k}}$ modulo $m$.
</p>
<p>
Calculate $\displaystyle{\sum M(10^{18},10^9,p\cdot q\cdot r)}$ for $1000\lt p\lt q\lt r\lt 5000$ and $p$,$q$,$r$ prime.
</p> | https://projecteuler.net/problem=365 | 162619462356610313 |
366 | Two players, Anton and Bernhard, are playing the following game.
There is one pile of $n$ stones.
The first player may remove any positive number of stones, but not the whole pile.
Thereafter, each player may remove at most twice the number of stones his opponent took on the previous move.
The player who removes the last stone wins.
E.g. $n=5$.
If the first player takes anything more than one stone the next player will be able to take all remaining stones.
If the first player takes one stone, leaving four, his opponent will take also one stone, leaving three stones.
The first player cannot take all three because he may take at most $2 \times 1=2$ stones. So let's say he takes also one stone, leaving $2$. The second player can take the two remaining stones and wins.
So $5$ is a losing position for the first player.
For some winning positions there is more than one possible move for the first player.
E.g. when $n=17$ the first player can remove one or four stones.
Let $M(n)$ be the maximum number of stones the first player can take from a winning position at his first turn and $M(n)=0$ for any other position.
$\sum M(n)$ for $n \le 100$ is $728$.
Find $\sum M(n)$ for $n \le 10^{18}$.
Give your answer modulo $10^8$. | <p>
Two players, Anton and Bernhard, are playing the following game.<br>
There is one pile of $n$ stones.<br>
The first player may remove any positive number of stones, but not the whole pile.<br>
Thereafter, each player may remove at most twice the number of stones his opponent took on the previous move.<br>
The player who removes the last stone wins.
</p>
<p>
E.g. $n=5$.<br>
If the first player takes anything more than one stone the next player will be able to take all remaining stones.<br>
If the first player takes one stone, leaving four, his opponent will take also one stone, leaving three stones.<br>
The first player cannot take all three because he may take at most $2 \times 1=2$ stones. So let's say he takes also one stone, leaving $2$. The second player can take the two remaining stones and wins.<br>
So $5$ is a losing position for the first player.<br>
For some winning positions there is more than one possible move for the first player.<br>
E.g. when $n=17$ the first player can remove one or four stones.
</p>
<p>
Let $M(n)$ be the maximum number of stones the first player can take from a winning position <i>at his first turn</i> and $M(n)=0$ for any other position.
</p>
<p>
$\sum M(n)$ for $n \le 100$ is $728$.
</p>
<p>
Find $\sum M(n)$ for $n \le 10^{18}$.
Give your answer modulo $10^8$.
</p> | https://projecteuler.net/problem=366 | 88351299 |
367 | Bozo sort, not to be confused with the slightly less efficient bogo sort, consists out of checking if the input sequence is sorted and if not swapping randomly two elements. This is repeated until eventually the sequence is sorted.
If we consider all permutations of the first $4$ natural numbers as input the expectation value of the number of swaps, averaged over all $4!$ input sequences is $24.75$.
The already sorted sequence takes $0$ steps.
In this problem we consider the following variant on bozo sort.
If the sequence is not in order we pick three elements at random and shuffle these three elements randomly.
All $3!=6$ permutations of those three elements are equally likely.
The already sorted sequence will take $0$ steps.
If we consider all permutations of the first $4$ natural numbers as input the expectation value of the number of shuffles, averaged over all $4!$ input sequences is $27.5$.
Consider as input sequences the permutations of the first $11$ natural numbers.
Averaged over all $11!$ input sequences, what is the expected number of shuffles this sorting algorithm will perform?
Give your answer rounded to the nearest integer. | <p>
<strong>Bozo sort</strong>, not to be confused with the slightly less efficient <strong>bogo sort</strong>, consists out of checking if the input sequence is sorted and if not swapping randomly two elements. This is repeated until eventually the sequence is sorted.
</p>
<p>
If we consider all permutations of the first $4$ natural numbers as input the expectation value of the number of swaps, averaged over all $4!$ input sequences is $24.75$.<br>
The already sorted sequence takes $0$ steps.
</p>
<p>
In this problem we consider the following variant on bozo sort.<br>
If the sequence is not in order we pick three elements at random and shuffle these three elements randomly.<br>
All $3!=6$ permutations of those three elements are equally likely. <br>
The already sorted sequence will take $0$ steps.<br>
If we consider all permutations of the first $4$ natural numbers as input the expectation value of the number of shuffles, averaged over all $4!$ input sequences is $27.5$. <br>
Consider as input sequences the permutations of the first $11$ natural numbers.<br>
Averaged over all $11!$ input sequences, what is the expected number of shuffles this sorting algorithm will perform?
</p>
<p>
Give your answer rounded to the nearest integer.
</p> | https://projecteuler.net/problem=367 | 48271207 |
368 | The harmonic series $1 + \frac 1 2 + \frac 1 3 + \frac 1 4 + \cdots$ is well known to be divergent.
If we however omit from this series every term where the denominator has a $9$ in it, the series remarkably enough converges to approximately $22.9206766193$.
This modified harmonic series is called the Kempner series.
Let us now consider another modified harmonic series by omitting from the harmonic series every term where the denominator has $3$ or more equal consecutive digits.
One can verify that out of the first $1200$ terms of the harmonic series, only $20$ terms will be omitted.
These $20$ omitted terms are:
$$\frac 1 {111}, \frac 1 {222}, \frac 1 {333}, \frac 1 {444}, \frac 1 {555}, \frac 1 {666}, \frac 1 {777}, \frac 1 {888}, \frac 1 {999}, \frac 1 {1000}, \frac 1 {1110},$$
$$\frac 1 {1111}, \frac 1 {1112}, \frac 1 {1113}, \frac 1 {1114}, \frac 1 {1115}, \frac 1 {1116}, \frac 1 {1117}, \frac 1 {1118}, \frac 1 {1119}.$$
This series converges as well.
Find the value the series converges to.
Give your answer rounded to $10$ digits behind the decimal point. | <p>The <strong>harmonic series</strong> $1 + \frac 1 2 + \frac 1 3 + \frac 1 4 + \cdots$ is well known to be divergent.</p>
<p>If we however omit from this series every term where the denominator has a $9$ in it, the series remarkably enough converges to approximately $22.9206766193$.<br>
This modified harmonic series is called the <strong>Kempner</strong> series.</p>
<p>Let us now consider another modified harmonic series by omitting from the harmonic series every term where the denominator has $3$ or more equal consecutive digits.
One can verify that out of the first $1200$ terms of the harmonic series, only $20$ terms will be omitted.<br>
These $20$ omitted terms are:</p>
<p>$$\frac 1 {111}, \frac 1 {222}, \frac 1 {333}, \frac 1 {444}, \frac 1 {555}, \frac 1 {666}, \frac 1 {777}, \frac 1 {888}, \frac 1 {999}, \frac 1 {1000}, \frac 1 {1110},$$
$$\frac 1 {1111}, \frac 1 {1112}, \frac 1 {1113}, \frac 1 {1114}, \frac 1 {1115}, \frac 1 {1116}, \frac 1 {1117}, \frac 1 {1118}, \frac 1 {1119}.$$</p>
<p>This series converges as well.</p>
<p>Find the value the series converges to.<br>
Give your answer rounded to $10$ digits behind the decimal point.</p> | https://projecteuler.net/problem=368 | 253.6135092068 |
369 | In a standard $52$ card deck of playing cards, a set of $4$ cards is a Badugi if it contains $4$ cards with no pairs and no two cards of the same suit.
Let $f(n)$ be the number of ways to choose $n$ cards with a $4$ card subset that is a Badugi. For example, there are $2598960$ ways to choose five cards from a standard $52$ card deck, of which $514800$ contain a $4$ card subset that is a Badugi, so $f(5) = 514800$.
Find $\sum f(n)$ for $4 \le n \le 13$. | <p>In a standard $52$ card deck of playing cards, a set of $4$ cards is a <strong>Badugi</strong> if it contains $4$ cards with no pairs and no two cards of the same suit.</p>
<p>Let $f(n)$ be the number of ways to choose $n$ cards with a $4$ card subset that is a Badugi. For example, there are $2598960$ ways to choose five cards from a standard $52$ card deck, of which $514800$ contain a $4$ card subset that is a Badugi, so $f(5) = 514800$.</p>
<p>Find $\sum f(n)$ for $4 \le n \le 13$.</p> | https://projecteuler.net/problem=369 | 862400558448 |
370 | Let us define a geometric triangle as an integer sided triangle with sides $a \le b \le c$ so that its sides form a geometric progression, i.e. $b^2 = a \cdot c$
An example of such a geometric triangle is the triangle with sides $a = 144$, $b = 156$ and $c = 169$.
There are $861805$ geometric triangles with perimeter $\le 10^6$.
How many geometric triangles exist with perimeter $\le 2.5 \cdot 10^{13}$? | <p>Let us define a <dfn>geometric triangle</dfn> as an integer sided triangle with sides $a \le b \le c$ so that its sides form a <strong>geometric progression</strong>, i.e. $b^2 = a \cdot c$</p>
<p>An example of such a geometric triangle is the triangle with sides $a = 144$, $b = 156$ and $c = 169$.</p>
<p>There are $861805$ geometric triangles with perimeter $\le 10^6$.</p>
<p>How many geometric triangles exist with perimeter $\le 2.5 \cdot 10^{13}$?</p> | https://projecteuler.net/problem=370 | 41791929448408 |
371 | Oregon licence plates consist of three letters followed by a three digit number (each digit can be from [0..9]).
While driving to work Seth plays the following game:
Whenever the numbers of two licence plates seen on his trip add to 1000 that's a win.
E.g. MIC-012 and HAN-988 is a win and RYU-500 and SET-500 too (as long as he sees them in the same trip).
Find the expected number of plates he needs to see for a win.
Give your answer rounded to 8 decimal places behind the decimal point.
Note: We assume that each licence plate seen is equally likely to have any three digit number on it. | <p>
Oregon licence plates consist of three letters followed by a three digit number (each digit can be from [0..9]).<br>
While driving to work Seth plays the following game:<br>
Whenever the numbers of two licence plates seen on his trip add to 1000 that's a win.
</p>
<p>
E.g. MIC-012 and HAN-988 is a win and RYU-500 and SET-500 too (as long as he sees them in the same trip).
</p><p>
</p><p>
Find the expected number of plates he needs to see for a win.<br>
Give your answer rounded to 8 decimal places behind the decimal point.
</p>
<p style="font-size:88%;">
<b>Note:</b> We assume that each licence plate seen is equally likely to have any three digit number on it.
</p> | https://projecteuler.net/problem=371 | 40.66368097 |
372 | Let $R(M, N)$ be the number of lattice points $(x, y)$ which satisfy $M\!\lt\!x\!\le\!N$, $M\!\lt\!y\!\le\!N$ and $\large\left\lfloor\!\frac{y^2}{x^2}\!\right\rfloor$ is odd.
We can verify that $R(0, 100) = 3019$ and $R(100, 10000) = 29750422$.
Find $R(2\cdot10^6, 10^9)$.
Note: $\lfloor x\rfloor$ represents the floor function. | <p>
Let $R(M, N)$ be the number of lattice points $(x, y)$ which satisfy $M\!\lt\!x\!\le\!N$, $M\!\lt\!y\!\le\!N$ and $\large\left\lfloor\!\frac{y^2}{x^2}\!\right\rfloor$ is odd.<br>
We can verify that $R(0, 100) = 3019$ and $R(100, 10000) = 29750422$.<br>
Find $R(2\cdot10^6, 10^9)$.
</p>
<p>
<u><i>Note</i></u>: $\lfloor x\rfloor$ represents the floor function.</p> | https://projecteuler.net/problem=372 | 301450082318807027 |
373 | Every triangle has a circumscribed circle that goes through the three vertices.
Consider all integer sided triangles for which the radius of the circumscribed circle is integral as well.
Let $S(n)$ be the sum of the radii of the circumscribed circles of all such triangles for which the radius does not exceed $n$.
$S(100)=4950$ and $S(1200)=1653605$.
Find $S(10^7)$. | <p>
Every triangle has a circumscribed circle that goes through the three vertices.
Consider all integer sided triangles for which the radius of the circumscribed circle is integral as well.
</p>
<p>
Let $S(n)$ be the sum of the radii of the circumscribed circles of all such triangles for which the radius does not exceed $n$.
</p>
<p>$S(100)=4950$ and $S(1200)=1653605$.
</p>
<p>
Find $S(10^7)$.
</p> | https://projecteuler.net/problem=373 | 727227472448913 |
374 | An integer partition of a number $n$ is a way of writing $n$ as a sum of positive integers.
Partitions that differ only in the order of their summands are considered the same.
A partition of $n$ into distinct parts is a partition of $n$ in which every part occurs at most once.
The partitions of $5$ into distinct parts are:
$5$, $4+1$ and $3+2$.
Let $f(n)$ be the maximum product of the parts of any such partition of $n$ into distinct parts and let $m(n)$ be the number of elements of any such partition of $n$ with that product.
So $f(5)=6$ and $m(5)=2$.
For $n=10$ the partition with the largest product is $10=2+3+5$, which gives $f(10)=30$ and $m(10)=3$.
And their product, $f(10) \cdot m(10) = 30 \cdot 3 = 90$.
It can be verified that
$\sum f(n) \cdot m(n)$ for $1 \le n \le 100 = 1683550844462$.
Find $\sum f(n) \cdot m(n)$ for $1 \le n \le 10^{14}$.
Give your answer modulo $982451653$, the $50$ millionth prime. | <p>An integer partition of a number $n$ is a way of writing $n$ as a sum of positive integers.</p>
<p>Partitions that differ only in the order of their summands are considered the same.
A partition of $n$ into <b>distinct parts</b> is a partition of $n$ in which every part occurs at most once.</p>
<p>The partitions of $5$ into distinct parts are:
<br>$5$, $4+1$ and $3+2$.</p>
<p>Let $f(n)$ be the maximum product of the parts of any such partition of $n$ into distinct parts and let $m(n)$ be the number of elements of any such partition of $n$ with that product.</p>
<p>So $f(5)=6$ and $m(5)=2$.</p>
<p>For $n=10$ the partition with the largest product is $10=2+3+5$, which gives $f(10)=30$ and $m(10)=3$.
<br>And their product, $f(10) \cdot m(10) = 30 \cdot 3 = 90$.</p>
<p>It can be verified that
<br>$\sum f(n) \cdot m(n)$ for $1 \le n \le 100 = 1683550844462$.</p>
<p>Find $\sum f(n) \cdot m(n)$ for $1 \le n \le 10^{14}$.
<br>Give your answer modulo $982451653$, the $50$ millionth prime.</p> | https://projecteuler.net/problem=374 | 334420941 |
375 | Let $S_n$ be an integer sequence produced with the following pseudo-random number generator:
$$\begin{align}
S_0 & = 290797 \\
S_{n+1} & = S_n^2 \bmod 50515093
\end{align}$$
Let $A(i, j)$ be the minimum of the numbers $S_i, S_{i+1}, \dots, S_j$ for $i\le j$.
Let $M(N) = \sum A(i, j)$ for $1 \le i \le j \le N$.
We can verify that $M(10) = 432256955$ and $M(10\,000) = 3264567774119$.
Find $M(2\,000\,000\,000)$. | <p>Let $S_n$ be an integer sequence produced with the following pseudo-random number generator:</p>
$$\begin{align}
S_0 & = 290797 \\
S_{n+1} & = S_n^2 \bmod 50515093
\end{align}$$
<p>
Let $A(i, j)$ be the minimum of the numbers $S_i, S_{i+1}, \dots, S_j$ for $i\le j$.<br>
Let $M(N) = \sum A(i, j)$ for $1 \le i \le j \le N$.<br>
We can verify that $M(10) = 432256955$ and $M(10\,000) = 3264567774119$.</p>
<p>
Find $M(2\,000\,000\,000)$.
</p> | https://projecteuler.net/problem=375 | 7435327983715286168 |
376 | Consider the following set of dice with nonstandard pips:
Die $A$: $1$ $4$ $4$ $4$ $4$ $4$
Die $B$: $2$ $2$ $2$ $5$ $5$ $5$
Die $C$: $3$ $3$ $3$ $3$ $3$ $6$
A game is played by two players picking a die in turn and rolling it. The player who rolls the highest value wins.
If the first player picks die $A$ and the second player picks die $B$ we get
$P(\text{second player wins}) = 7/12 \gt 1/2$.
If the first player picks die $B$ and the second player picks die $C$ we get
$P(\text{second player wins}) = 7/12 \gt 1/2$.
If the first player picks die $C$ and the second player picks die $A$ we get
$P(\text{second player wins}) = 25/36 \gt 1/2$.
So whatever die the first player picks, the second player can pick another die and have a larger than $50\%$ chance of winning.
A set of dice having this property is called a nontransitive set of dice.
We wish to investigate how many sets of nontransitive dice exist. We will assume the following conditions:
- There are three six-sided dice with each side having between $1$ and $N$ pips, inclusive.
- Dice with the same set of pips are equal, regardless of which side on the die the pips are located.
- The same pip value may appear on multiple dice; if both players roll the same value neither player wins.
- The sets of dice $\{A,B,C\}$, $\{B,C,A\}$ and $\{C,A,B\}$ are the same set.
For $N = 7$ we find there are $9780$ such sets.
How many are there for $N = 30$? | <p>
Consider the following set of dice with nonstandard pips:
</p>
<p>
Die $A$: $1$ $4$ $4$ $4$ $4$ $4$<br>
Die $B$: $2$ $2$ $2$ $5$ $5$ $5$<br>
Die $C$: $3$ $3$ $3$ $3$ $3$ $6$<br></p>
<p>
A game is played by two players picking a die in turn and rolling it. The player who rolls the highest value wins.
</p>
<p>
If the first player picks die $A$ and the second player picks die $B$ we get<br>
$P(\text{second player wins}) = 7/12 \gt 1/2$.</p>
<p>
If the first player picks die $B$ and the second player picks die $C$ we get<br>
$P(\text{second player wins}) = 7/12 \gt 1/2$.</p>
<p>
If the first player picks die $C$ and the second player picks die $A$ we get<br>
$P(\text{second player wins}) = 25/36 \gt 1/2$.</p>
<p>
So whatever die the first player picks, the second player can pick another die and have a larger than $50\%$ chance of winning.<br>
A set of dice having this property is called a <strong>nontransitive set of dice</strong>.
</p>
<p>
We wish to investigate how many sets of nontransitive dice exist. We will assume the following conditions:</p><ul><li>There are three six-sided dice with each side having between $1$ and $N$ pips, inclusive.</li>
<li>Dice with the same set of pips are equal, regardless of which side on the die the pips are located.</li>
<li>The same pip value may appear on multiple dice; if both players roll the same value neither player wins.</li>
<li>The sets of dice $\{A,B,C\}$, $\{B,C,A\}$ and $\{C,A,B\}$ are the same set.</li>
</ul><p>
For $N = 7$ we find there are $9780$ such sets.<br>
How many are there for $N = 30$?
</p> | https://projecteuler.net/problem=376 | 973059630185670 |
377 | There are $16$ positive integers that do not have a zero in their digits and that have a digital sum equal to $5$, namely:
$5$, $14$, $23$, $32$, $41$, $113$, $122$, $131$, $212$, $221$, $311$, $1112$, $1121$, $1211$, $2111$ and $11111$.
Their sum is $17891$.
Let $f(n)$ be the sum of all positive integers that do not have a zero in their digits and have a digital sum equal to $n$.
Find $\displaystyle \sum_{i=1}^{17} f(13^i)$.
Give the last $9$ digits as your answer. | <p>
There are $16$ positive integers that do not have a zero in their digits and that have a digital sum equal to $5$, namely: <br>
$5$, $14$, $23$, $32$, $41$, $113$, $122$, $131$, $212$, $221$, $311$, $1112$, $1121$, $1211$, $2111$ and $11111$.<br>
Their sum is $17891$.
</p>
<p>
Let $f(n)$ be the sum of all positive integers that do not have a zero in their digits and have a digital sum equal to $n$.
</p>
<p>
Find $\displaystyle \sum_{i=1}^{17} f(13^i)$.<br>
Give the last $9$ digits as your answer.
</p> | https://projecteuler.net/problem=377 | 732385277 |
378 | Let $T(n)$ be the nth triangle number, so $T(n) = \dfrac{n(n + 1)}{2}$.
Let $dT(n)$ be the number of divisors of $T(n)$.
E.g.: $T(7) = 28$ and $dT(7) = 6$.
Let $Tr(n)$ be the number of triples $(i, j, k)$ such that $1 \le i \lt j \lt k \le n$ and $dT(i) \gt dT(j) \gt dT(k)$.
$Tr(20) = 14$, $Tr(100) = 5772$, and $Tr(1000) = 11174776$.
Find $Tr(60 000 000)$.
Give the last 18 digits of your answer. | <p>Let $T(n)$ be the n<sup>th</sup> triangle number, so $T(n) = \dfrac{n(n + 1)}{2}$.</p>
<p>Let $dT(n)$ be the number of divisors of $T(n)$.<br>
E.g.: $T(7) = 28$ and $dT(7) = 6$.</p>
<p>Let $Tr(n)$ be the number of triples $(i, j, k)$ such that $1 \le i \lt j \lt k \le n$ and $dT(i) \gt dT(j) \gt dT(k)$.<br>
$Tr(20) = 14$, $Tr(100) = 5772$, and $Tr(1000) = 11174776$.</p>
<p>Find $Tr(60 000 000)$. <br>
Give the last 18 digits of your answer.</p> | https://projecteuler.net/problem=378 | 147534623725724718 |
379 | Let $f(n)$ be the number of couples $(x, y)$ with $x$ and $y$ positive integers, $x \le y$ and the least common multiple of $x$ and $y$ equal to $n$.
Let $g$ be the summatory function of $f$, i.e.:
$g(n) = \sum f(i)$ for $1 \le i \le n$.
You are given that $g(10^6) = 37429395$.
Find $g(10^{12})$. | <p>
Let $f(n)$ be the number of couples $(x, y)$ with $x$ and $y$ positive integers, $x \le y$ and the least common multiple of $x$ and $y$ equal to $n$.
</p>
<p>
Let $g$ be the <strong>summatory function</strong> of $f$, i.e.:
$g(n) = \sum f(i)$ for $1 \le i \le n$.
</p><p>
You are given that $g(10^6) = 37429395$.
</p>
<p>
Find $g(10^{12})$.
</p> | https://projecteuler.net/problem=379 | 132314136838185 |
380 | An $m \times n$ maze is an $m \times n$ rectangular grid with walls placed between grid cells such that there is exactly one path from the top-left square to any other square.
The following are examples of a $9 \times 12$ maze and a $15 \times 20$ maze:
Let $C(m,n)$ be the number of distinct $m \times n$ mazes. Mazes which can be formed by rotation and reflection from another maze are considered distinct.
It can be verified that $C(1,1) = 1$, $C(2,2) = 4$, $C(3,4) = 2415$, and $C(9,12) = 2.5720\mathrm e46$ (in scientific notation rounded to $5$ significant digits).
Find $C(100,500)$ and write your answer in scientific notation rounded to $5$ significant digits.
When giving your answer, use a lowercase e to separate mantissa and exponent.
E.g. if the answer is $1234567891011$ then the answer format would be 1.2346e12. | <p>
An $m \times n$ maze is an $m \times n$ rectangular grid with walls placed between grid cells such that there is exactly one path from the top-left square to any other square. <br>The following are examples of a $9 \times 12$ maze and a $15 \times 20$ maze:
</p>
<p class="center">
<img src="resources/images/0380_mazes.gif?1678992056" class="dark_img" alt="0380_mazes.gif"></p>
<p>
Let $C(m,n)$ be the number of distinct $m \times n$ mazes. Mazes which can be formed by rotation and reflection from another maze are considered distinct.
</p>
<p>
It can be verified that $C(1,1) = 1$, $C(2,2) = 4$, $C(3,4) = 2415$, and $C(9,12) = 2.5720\mathrm e46$ (in scientific notation rounded to $5$ significant digits).<br>
Find $C(100,500)$ and write your answer in scientific notation rounded to $5$ significant digits.
</p>
<p>
When giving your answer, use a lowercase e to separate mantissa and exponent.
E.g. if the answer is $1234567891011$ then the answer format would be 1.2346e12.
</p> | https://projecteuler.net/problem=380 | 6.3202e25093 |
381 | For a prime $p$ let $S(p) = (\sum (p-k)!) \bmod (p)$ for $1 \le k \le 5$.
For example, if $p=7$,
$(7-1)! + (7-2)! + (7-3)! + (7-4)! + (7-5)! = 6! + 5! + 4! + 3! + 2! = 720+120+24+6+2 = 872$.
As $872 \bmod (7) = 4$, $S(7) = 4$.
It can be verified that $\sum S(p) = 480$ for $5 \le p \lt 100$.
Find $\sum S(p)$ for $5 \le p \lt 10^8$. | <p>
For a prime $p$ let $S(p) = (\sum (p-k)!) \bmod (p)$ for $1 \le k \le 5$.
</p>
<p>
For example, if $p=7$,<br>
$(7-1)! + (7-2)! + (7-3)! + (7-4)! + (7-5)! = 6! + 5! + 4! + 3! + 2! = 720+120+24+6+2 = 872$.<br>
As $872 \bmod (7) = 4$, $S(7) = 4$.
</p>
<p>
It can be verified that $\sum S(p) = 480$ for $5 \le p \lt 100$.
</p>
<p>
Find $\sum S(p)$ for $5 \le p \lt 10^8$.
</p> | https://projecteuler.net/problem=381 | 139602943319822 |
382 | A polygon is a flat shape consisting of straight line segments that are joined to form a closed chain or circuit. A polygon consists of at least three sides and does not self-intersect.
A set $S$ of positive numbers is said to generate a polygon $P$ if:
- no two sides of $P$ are the same length,
- the length of every side of $P$ is in $S$, and
- $S$ contains no other value.
For example:
The set $\{3, 4, 5\}$ generates a polygon with sides $3$, $4$, and $5$ (a triangle).
The set $\{6, 9, 11, 24\}$ generates a polygon with sides $6$, $9$, $11$, and $24$ (a quadrilateral).
The sets $\{1, 2, 3\}$ and $\{2, 3, 4, 9\}$ do not generate any polygon at all.
Consider the sequence $s$, defined as follows:
- $s_1 = 1$, $s_2 = 2$, $s_3 = 3$
- $s_n = s_{n-1} + s_{n-3}$ for $n \gt 3$.
Let $U_n$ be the set $\{s_1, s_2, \dots, s_n\}$. For example, $U_{10} = \{1, 2, 3, 4, 6, 9, 13, 19, 28, 41\}$.
Let $f(n)$ be the number of subsets of $U_n$ which generate at least one polygon.
For example, $f(5) = 7$, $f(10) = 501$ and $f(25) = 18635853$.
Find the last $9$ digits of $f(10^{18})$. | <p>
A <strong>polygon</strong> is a flat shape consisting of straight line segments that are joined to form a closed chain or circuit. A polygon consists of at least three sides and does not self-intersect.
</p>
<p>
A set $S$ of positive numbers is said to <dfn>generate a polygon</dfn> $P$ if:</p><ul><li> no two sides of $P$ are the same length,
</li><li> the length of every side of $P$ is in $S$, and
</li><li> $S$ contains no other value.
</li></ul><p>
For example:<br>
The set $\{3, 4, 5\}$ generates a polygon with sides $3$, $4$, and $5$ (a triangle).<br>
The set $\{6, 9, 11, 24\}$ generates a polygon with sides $6$, $9$, $11$, and $24$ (a quadrilateral).<br>
The sets $\{1, 2, 3\}$ and $\{2, 3, 4, 9\}$ do not generate any polygon at all.<br></p>
<p>
Consider the sequence $s$, defined as follows:</p><ul><li>$s_1 = 1$, $s_2 = 2$, $s_3 = 3$
</li><li>$s_n = s_{n-1} + s_{n-3}$ for $n \gt 3$.
</li></ul><p>
Let $U_n$ be the set $\{s_1, s_2, \dots, s_n\}$. For example, $U_{10} = \{1, 2, 3, 4, 6, 9, 13, 19, 28, 41\}$.<br>
Let $f(n)$ be the number of subsets of $U_n$ which generate at least one polygon.<br>
For example, $f(5) = 7$, $f(10) = 501$ and $f(25) = 18635853$.
</p>
<p>
Find the last $9$ digits of $f(10^{18})$.
</p> | https://projecteuler.net/problem=382 | 697003956 |
383 | Let $f_5(n)$ be the largest integer $x$ for which $5^x$ divides $n$.
For example, $f_5(625000) = 7$.
Let $T_5(n)$ be the number of integers $i$ which satisfy $f_5((2 \cdot i - 1)!) \lt 2 \cdot f_5(i!)$ and $1 \le i \le n$.
It can be verified that $T_5(10^3) = 68$ and $T_5(10^9) = 2408210$.
Find $T_5(10^{18})$. | <p>
Let $f_5(n)$ be the largest integer $x$ for which $5^x$ divides $n$.<br>
For example, $f_5(625000) = 7$.
</p>
<p>
Let $T_5(n)$ be the number of integers $i$ which satisfy $f_5((2 \cdot i - 1)!) \lt 2 \cdot f_5(i!)$ and $1 \le i \le n$.<br>
It can be verified that $T_5(10^3) = 68$ and $T_5(10^9) = 2408210$.
</p>
<p>
Find $T_5(10^{18})$.
</p> | https://projecteuler.net/problem=383 | 22173624649806 |
384 | Define the sequence $a(n)$ as the number of adjacent pairs of ones in the binary expansion of $n$ (possibly overlapping).
E.g.: $a(5) = a(101_2) = 0$, $a(6) = a(110_2) = 1$, $a(7) = a(111_2) = 2$.
Define the sequence $b(n) = (-1)^{a(n)}$.
This sequence is called the Rudin-Shapiro sequence.
Also consider the summatory sequence of $b(n)$: $s(n) = \sum \limits_{i = 0}^n b(i)$.
The first couple of values of these sequences are:
| $n$ | $0$ | $1$ | $2$ | $3$ | $4$ | $5$ | $6$ | $7$ |
| $a(n)$ | $0$ | $0$ | $0$ | $1$ | $0$ | $0$ | $1$ | $2$ |
| $b(n)$ | $1$ | $1$ | $1$ | $-1$ | $1$ | $1$ | $-1$ | $1$ |
| $s(n)$ | $1$ | $2$ | $3$ | $2$ | $3$ | $4$ | $3$ | $4$ |
The sequence $s(n)$ has the remarkable property that all elements are positive and every positive integer $k$ occurs exactly $k$ times.
Define $g(t,c)$, with $1 \le c \le t$, as the index in $s(n)$ for which $t$ occurs for the $c$'th time in $s(n)$.
E.g.: $g(3,3) = 6$, $g(4,2) = 7$ and $g(54321,12345) = 1220847710$.
Let $F(n)$ be the Fibonacci sequence defined by:
$F(0)=F(1)=1$ and
$F(n)=F(n-1)+F(n-2)$ for $n \gt 1$.
Define $GF(t)=g(F(t),F(t-1))$.
Find $\sum GF(t)$ for $2 \le t \le 45$. | <p>Define the sequence $a(n)$ as the number of adjacent pairs of ones in the binary expansion of $n$ (possibly overlapping).
<br>E.g.: $a(5) = a(101_2) = 0$, $a(6) = a(110_2) = 1$, $a(7) = a(111_2) = 2$.</p>
<p>Define the sequence $b(n) = (-1)^{a(n)}$.
<br>This sequence is called the <strong>Rudin-Shapiro</strong> sequence.</p>
<p>Also consider the summatory sequence of $b(n)$: $s(n) = \sum \limits_{i = 0}^n b(i)$.</p>
<p>The first couple of values of these sequences are:</p>
<table align="center"><tr>
<td align="center" width="30">$n$</td>
<td align="right" width="30">$0$</td>
<td align="right" width="30">$1$</td>
<td align="right" width="30">$2$</td>
<td align="right" width="30">$3$</td>
<td align="right" width="30">$4$</td>
<td align="right" width="30">$5$</td>
<td align="right" width="30">$6$</td>
<td align="right" width="30">$7$</td>
</tr><tr>
<td align="center" width="30">$a(n)$</td>
<td align="right" width="30">$0$</td>
<td align="right" width="30">$0$</td>
<td align="right" width="30">$0$</td>
<td align="right" width="30">$1$</td>
<td align="right" width="30">$0$</td>
<td align="right" width="30">$0$</td>
<td align="right" width="30">$1$</td>
<td align="right" width="30">$2$</td>
</tr><tr>
<td align="center" width="30">$b(n)$</td>
<td align="right" width="30">$1$</td>
<td align="right" width="30">$1$</td>
<td align="right" width="30">$1$</td>
<td align="right" width="30">$-1$</td>
<td align="right" width="30">$1$</td>
<td align="right" width="30">$1$</td>
<td align="right" width="30">$-1$</td>
<td align="right" width="30">$1$</td>
</tr><tr>
<td align="center" width="30">$s(n)$</td>
<td align="right" width="30">$1$</td>
<td align="right" width="30">$2$</td>
<td align="right" width="30">$3$</td>
<td align="right" width="30">$2$</td>
<td align="right" width="30">$3$</td>
<td align="right" width="30">$4$</td>
<td align="right" width="30">$3$</td>
<td align="right" width="30">$4$</td>
</tr></table>
<p>The sequence $s(n)$ has the remarkable property that all elements are positive and every positive integer $k$ occurs exactly $k$ times.</p>
<p>Define $g(t,c)$, with $1 \le c \le t$, as the index in $s(n)$ for which $t$ occurs for the $c$'th time in $s(n)$.
<br>E.g.: $g(3,3) = 6$, $g(4,2) = 7$ and $g(54321,12345) = 1220847710$.</p>
<p>Let $F(n)$ be the Fibonacci sequence defined by:
<br>$F(0)=F(1)=1$ and
<br>$F(n)=F(n-1)+F(n-2)$ for $n \gt 1$.</p>
<p>Define $GF(t)=g(F(t),F(t-1))$.</p>
<p>Find $\sum GF(t)$ for $2 \le t \le 45$.</p> | https://projecteuler.net/problem=384 | 3354706415856332783 |
385 | For any triangle $T$ in the plane, it can be shown that there is a unique ellipse with largest area that is completely inside $T$.
For a given $n$, consider triangles $T$ such that:
- the vertices of $T$ have integer coordinates with absolute value $\le n$, and
- the foci1 of the largest-area ellipse inside $T$ are $(\sqrt{13},0)$ and $(-\sqrt{13},0)$.
Let $A(n)$ be the sum of the areas of all such triangles.
For example, if $n = 8$, there are two such triangles. Their vertices are $(-4,-3),(-4,3),(8,0)$ and $(4,3),(4,-3),(-8,0)$, and the area of each triangle is $36$. Thus $A(8) = 36 + 36 = 72$.
It can be verified that $A(10) = 252$, $A(100) = 34632$ and $A(1000) = 3529008$.
Find $A(1\,000\,000\,000)$.
1The foci (plural of focus) of an ellipse are two points $A$ and $B$ such that for every point $P$ on the boundary of the ellipse, $AP + PB$ is constant. | <p>
For any triangle $T$ in the plane, it can be shown that there is a unique ellipse with largest area that is completely inside $T$.
</p><p align="center">
<img src="resources/images/0385_ellipsetriangle.png?1678992053" alt="0385_ellipsetriangle.png"></p>
<p>
For a given $n$, consider triangles $T$ such that:<br>
- the vertices of $T$ have integer coordinates with absolute value $\le n$, and <br>
- the <strong>foci</strong><sup>1</sup> of the largest-area ellipse inside $T$ are $(\sqrt{13},0)$ and $(-\sqrt{13},0)$.<br>
Let $A(n)$ be the sum of the areas of all such triangles.
</p>
<p>
For example, if $n = 8$, there are two such triangles. Their vertices are $(-4,-3),(-4,3),(8,0)$ and $(4,3),(4,-3),(-8,0)$, and the area of each triangle is $36$. Thus $A(8) = 36 + 36 = 72$.
</p>
<p>
It can be verified that $A(10) = 252$, $A(100) = 34632$ and $A(1000) = 3529008$.
</p>
<p>
Find $A(1\,000\,000\,000)$.
</p>
<p>
<span style="font-size:smaller;"><sup>1</sup>The <strong>foci</strong> (plural of <strong>focus</strong>) of an ellipse are two points $A$ and $B$ such that for every point $P$ on the boundary of the ellipse, $AP + PB$ is constant.</span>
</p> | https://projecteuler.net/problem=385 | 3776957309612153700 |
386 | Let $n$ be an integer and $S(n)$ be the set of factors of $n$.
A subset $A$ of $S(n)$ is called an antichain of $S(n)$ if $A$ contains only one element or if none of the elements of $A$ divides any of the other elements of $A$.
For example: $S(30) = \{1, 2, 3, 5, 6, 10, 15, 30\}$.
$\{2, 5, 6\}$ is not an antichain of $S(30)$.
$\{2, 3, 5\}$ is an antichain of $S(30)$.
Let $N(n)$ be the maximum length of an antichain of $S(n)$.
Find $\sum N(n)$ for $1 \le n \le 10^8$. | <p>Let $n$ be an integer and $S(n)$ be the set of factors of $n$.</p>
<p>A subset $A$ of $S(n)$ is called an <strong>antichain</strong> of $S(n)$ if $A$ contains only one element or if none of the elements of $A$ divides any of the other elements of $A$.</p>
<p>For example: $S(30) = \{1, 2, 3, 5, 6, 10, 15, 30\}$.
<br>$\{2, 5, 6\}$ is not an antichain of $S(30)$.
<br>$\{2, 3, 5\}$ is an antichain of $S(30)$.</p>
<p>Let $N(n)$ be the maximum length of an antichain of $S(n)$.</p>
<p>Find $\sum N(n)$ for $1 \le n \le 10^8$.</p> | https://projecteuler.net/problem=386 | 528755790 |
387 | A Harshad or Niven number is a number that is divisible by the sum of its digits.
$201$ is a Harshad number because it is divisible by $3$ (the sum of its digits.)
When we truncate the last digit from $201$, we get $20$, which is a Harshad number.
When we truncate the last digit from $20$, we get $2$, which is also a Harshad number.
Let's call a Harshad number that, while recursively truncating the last digit, always results in a Harshad number a right truncatable Harshad number.
Also:
$201/3=67$ which is prime.
Let's call a Harshad number that, when divided by the sum of its digits, results in a prime a strong Harshad number.
Now take the number $2011$ which is prime.
When we truncate the last digit from it we get $201$, a strong Harshad number that is also right truncatable.
Let's call such primes strong, right truncatable Harshad primes.
You are given that the sum of the strong, right truncatable Harshad primes less than $10000$ is $90619$.
Find the sum of the strong, right truncatable Harshad primes less than $10^{14}$. | <p>A <strong>Harshad or Niven number</strong> is a number that is divisible by the sum of its digits.
<br>$201$ is a Harshad number because it is divisible by $3$ (the sum of its digits.)
<br>When we truncate the last digit from $201$, we get $20$, which is a Harshad number.
<br>When we truncate the last digit from $20$, we get $2$, which is also a Harshad number.
<br>Let's call a Harshad number that, while recursively truncating the last digit, always results in a Harshad number a <dfn>right truncatable Harshad number</dfn>.</p>
<p>Also:
<br>$201/3=67$ which is prime.
<br>Let's call a Harshad number that, when divided by the sum of its digits, results in a prime a <dfn>strong Harshad number</dfn>.</p>
<p>Now take the number $2011$ which is prime.
<br>When we truncate the last digit from it we get $201$, a strong Harshad number that is also right truncatable.
<br>Let's call such primes <dfn>strong, right truncatable Harshad primes</dfn>.</p>
<p>You are given that the sum of the strong, right truncatable Harshad primes less than $10000$ is $90619$.</p>
<p>Find the sum of the strong, right truncatable Harshad primes less than $10^{14}$.</p> | https://projecteuler.net/problem=387 | 696067597313468 |
388 | Consider all lattice points $(a,b,c)$ with $0 \le a,b,c \le N$.
From the origin $O(0,0,0)$ all lines are drawn to the other lattice points.
Let $D(N)$ be the number of distinct such lines.
You are given that $D(1\,000\,000) = 831909254469114121$.
Find $D(10^{10})$. Give as your answer the first nine digits followed by the last nine digits. | <p>
Consider all lattice points $(a,b,c)$ with $0 \le a,b,c \le N$.
</p>
<p>
From the origin $O(0,0,0)$ all lines are drawn to the other lattice points.<br>
Let $D(N)$ be the number of <i>distinct</i> such lines.
</p>
<p>
You are given that $D(1\,000\,000) = 831909254469114121$.
</p><p>
Find $D(10^{10})$. Give as your answer the first nine digits followed by the last nine digits.
</p> | https://projecteuler.net/problem=388 | 831907372805129931 |
389 | An unbiased single $4$-sided die is thrown and its value, $T$, is noted.
$T$ unbiased $6$-sided dice are thrown and their scores are added together. The sum, $C$, is noted.
$C$ unbiased $8$-sided dice are thrown and their scores are added together. The sum, $O$, is noted.
$O$ unbiased $12$-sided dice are thrown and their scores are added together. The sum, $D$, is noted.
$D$ unbiased $20$-sided dice are thrown and their scores are added together. The sum, $I$, is noted.
Find the variance of $I$, and give your answer rounded to $4$ decimal places. | <p>
An unbiased single $4$-sided die is thrown and its value, $T$, is noted.<br>$T$ unbiased $6$-sided dice are thrown and their scores are added together. The sum, $C$, is noted.<br>$C$ unbiased $8$-sided dice are thrown and their scores are added together. The sum, $O$, is noted.<br>$O$ unbiased $12$-sided dice are thrown and their scores are added together. The sum, $D$, is noted.<br>$D$ unbiased $20$-sided dice are thrown and their scores are added together. The sum, $I$, is noted.<br>
Find the <strong>variance</strong> of $I$, and give your answer rounded to $4$ decimal places.
</p> | https://projecteuler.net/problem=389 | 2406376.3623 |
390 | Consider the triangle with sides $\sqrt 5$, $\sqrt {65}$ and $\sqrt {68}$.
It can be shown that this triangle has area $9$.
$S(n)$ is the sum of the areas of all triangles with sides $\sqrt{1+b^2}$, $\sqrt {1+c^2}$ and $\sqrt{b^2+c^2}\,$ (for positive integers $b$ and $c$) that have an integral area not exceeding $n$.
The example triangle has $b=2$ and $c=8$.
$S(10^6)=18018206$.
Find $S(10^{10})$. | <p>Consider the triangle with sides $\sqrt 5$, $\sqrt {65}$ and $\sqrt {68}$.
It can be shown that this triangle has area $9$.</p>
<p>$S(n)$ is the sum of the areas of all triangles with sides $\sqrt{1+b^2}$, $\sqrt {1+c^2}$ and $\sqrt{b^2+c^2}\,$ (for positive integers $b$ and $c$) that have an integral area not exceeding $n$.</p>
<p>The example triangle has $b=2$ and $c=8$.</p>
<p>$S(10^6)=18018206$.</p>
<p>Find $S(10^{10})$.</p> | https://projecteuler.net/problem=390 | 2919133642971 |
391 | Let $s_k$ be the number of 1’s when writing the numbers from 0 to $k$ in binary.
For example, writing 0 to 5 in binary, we have $0, 1, 10, 11, 100, 101$. There are seven 1’s, so $s_5 = 7$.
The sequence $S = \{s_k : k \ge 0\}$ starts $\{0, 1, 2, 4, 5, 7, 9, 12, ...\}$.
A game is played by two players. Before the game starts, a number $n$ is chosen. A counter $c$ starts at 0. At each turn, the player chooses a number from 1 to $n$ (inclusive) and increases $c$ by that number. The resulting value of $c$ must be a member of $S$. If there are no more valid moves, then the player loses.
For example, with $n = 5$ and starting with $c = 0$:
Player 1 chooses 4, so $c$ becomes $0 + 4 = 4$.
Player 2 chooses 5, so $c$ becomes $4 + 5 = 9$.
Player 1 chooses 3, so $c$ becomes $9 + 3 = 12$.
etc.
Note that $c$ must always belong to $S$, and each player can increase $c$ by at most $n$.
Let $M(n)$ be the highest number that the first player could choose at the start to force a win, and $M(n) = 0$ if there is no such move. For example, $M(2) = 2$, $M(7) = 1$, and $M(20) = 4$.
It can be verified that $\sum{M(n)^3} = 8150$ for $1 \le n \le 20$.
Find $\sum{M(n)^3}$ for $1 \le n \le 1000$. | <p>Let $s_k$ be the number of 1’s when writing the numbers from 0 to $k$ in binary.<br>
For example, writing 0 to 5 in binary, we have $0, 1, 10, 11, 100, 101$. There are seven 1’s, so $s_5 = 7$.<br>
The sequence $S = \{s_k : k \ge 0\}$ starts $\{0, 1, 2, 4, 5, 7, 9, 12, ...\}$.</p>
<p>A game is played by two players. Before the game starts, a number $n$ is chosen. A counter $c$ starts at 0. At each turn, the player chooses a number from 1 to $n$ (inclusive) and increases $c$ by that number. The resulting value of $c$ must be a member of $S$. If there are no more valid moves, then the player loses.</p>
<p>For example, with $n = 5$ and starting with $c = 0$:</p>
<p>Player 1 chooses 4, so $c$ becomes $0 + 4 = 4$.<br>
Player 2 chooses 5, so $c$ becomes $4 + 5 = 9$.<br>
Player 1 chooses 3, so $c$ becomes $9 + 3 = 12$.<br>
etc.</p>
<p>Note that $c$ must always belong to $S$, and each player can increase $c$ by at most $n$.</p>
<p>Let $M(n)$ be the highest number that the first player could choose at the start to force a win, and $M(n) = 0$ if there is no such move. For example, $M(2) = 2$, $M(7) = 1$, and $M(20) = 4$.</p>
<p>It can be verified that $\sum{M(n)^3} = 8150$ for $1 \le n \le 20$.</p>
<p>Find $\sum{M(n)^3}$ for $1 \le n \le 1000$.</p> | https://projecteuler.net/problem=391 | 61029882288 |
392 | A rectilinear grid is an orthogonal grid where the spacing between the gridlines does not have to be equidistant.
An example of such grid is logarithmic graph paper.
Consider rectilinear grids in the Cartesian coordinate system with the following properties:
- The gridlines are parallel to the axes of the Cartesian coordinate system.
- There are $N+2$ vertical and $N+2$ horizontal gridlines. Hence there are $(N+1) \times (N+1)$ rectangular cells.
- The equations of the two outer vertical gridlines are $x = -1$ and $x = 1$.
- The equations of the two outer horizontal gridlines are $y = -1$ and $y = 1$.
- The grid cells are colored red if they overlap with the unit circleThe unit circle is the circle that has radius $1$ and is centered at the origin, black otherwise.
For this problem we would like you to find the positions of the remaining $N$ inner horizontal and $N$ inner vertical gridlines so that the area occupied by the red cells is minimized.
E.g. here is a picture of the solution for $N = 10$:
The area occupied by the red cells for $N = 10$ rounded to $10$ digits behind the decimal point is $3.3469640797$.
Find the positions for $N = 400$.
Give as your answer the area occupied by the red cells rounded to $10$ digits behind the decimal point. | <p>
A rectilinear grid is an orthogonal grid where the spacing between the gridlines does not have to be equidistant.<br>
An example of such grid is logarithmic graph paper.
</p>
<p>
Consider rectilinear grids in the Cartesian coordinate system with the following properties:<br></p><ul><li>The gridlines are parallel to the axes of the Cartesian coordinate system.</li><li>There are $N+2$ vertical and $N+2$ horizontal gridlines. Hence there are $(N+1) \times (N+1)$ rectangular cells.</li><li>The equations of the two outer vertical gridlines are $x = -1$ and $x = 1$.</li><li>The equations of the two outer horizontal gridlines are $y = -1$ and $y = 1$.</li><li>The grid cells are colored red if they overlap with the <strong class="tooltip">unit circle<span class="tooltiptext">The unit circle is the circle that has radius $1$ and is centered at the origin</span></strong>, black otherwise.</li></ul>For this problem we would like you to find the positions of the remaining $N$ inner horizontal and $N$ inner vertical gridlines so that the area occupied by the red cells is minimized.
<p>
E.g. here is a picture of the solution for $N = 10$:
</p><p align="center">
<img src="resources/images/0392_gridlines.png?1678992053" alt="0392_gridlines.png"></p>
The area occupied by the red cells for $N = 10$ rounded to $10$ digits behind the decimal point is $3.3469640797$.
<p>
Find the positions for $N = 400$.<br>
Give as your answer the area occupied by the red cells rounded to $10$ digits behind the decimal point.
</p> | https://projecteuler.net/problem=392 | 3.1486734435 |
393 | An $n \times n$ grid of squares contains $n^2$ ants, one ant per square.
All ants decide to move simultaneously to an adjacent square (usually $4$ possibilities, except for ants on the edge of the grid or at the corners).
We define $f(n)$ to be the number of ways this can happen without any ants ending on the same square and without any two ants crossing the same edge between two squares.
You are given that $f(4) = 88$.
Find $f(10)$. | <p>
An $n \times n$ grid of squares contains $n^2$ ants, one ant per square.<br>
All ants decide to move simultaneously to an adjacent square (usually $4$ possibilities, except for ants on the edge of the grid or at the corners).<br>
We define $f(n)$ to be the number of ways this can happen without any ants ending on the same square and without any two ants crossing the same edge between two squares.
</p>
<p>
You are given that $f(4) = 88$.<br>
Find $f(10)$.
</p> | https://projecteuler.net/problem=393 | 112398351350823112 |
394 | Jeff eats a pie in an unusual way.
The pie is circular. He starts with slicing an initial cut in the pie along a radius.
While there is at least a given fraction $F$ of pie left, he performs the following procedure:
- He makes two slices from the pie centre to any point of what is remaining of the pie border, any point on the remaining pie border equally likely. This will divide the remaining pie into three pieces.
- Going counterclockwise from the initial cut, he takes the first two pie pieces and eats them.
When less than a fraction $F$ of pie remains, he does not repeat this procedure. Instead, he eats all of the remaining pie.
For $x \ge 1$, let $E(x)$ be the expected number of times Jeff repeats the procedure above with $F = 1/x$.
It can be verified that $E(1) = 1$, $E(2) \approx 1.2676536759$, and $E(7.5) \approx 2.1215732071$.
Find $E(40)$ rounded to $10$ decimal places behind the decimal point. | <p>
Jeff eats a pie in an unusual way.<br>
The pie is circular. He starts with slicing an initial cut in the pie along a radius.<br>
While there is at least a given fraction $F$ of pie left, he performs the following procedure:<br>
- He makes two slices from the pie centre to any point of what is remaining of the pie border, any point on the remaining pie border equally likely. This will divide the remaining pie into three pieces.<br>
- Going counterclockwise from the initial cut, he takes the first two pie pieces and eats them.<br>
When less than a fraction $F$ of pie remains, he does not repeat this procedure. Instead, he eats all of the remaining pie.
</p>
<p align="center">
<img src="resources/images/0394_eatpie.gif?1678992056" alt="0394_eatpie.gif"></p>
<p>
For $x \ge 1$, let $E(x)$ be the expected number of times Jeff repeats the procedure above with $F = 1/x$.<br>
It can be verified that $E(1) = 1$, $E(2) \approx 1.2676536759$, and $E(7.5) \approx 2.1215732071$.
</p>
<p>
Find $E(40)$ rounded to $10$ decimal places behind the decimal point.
</p> | https://projecteuler.net/problem=394 | 3.2370342194 |
395 | The Pythagorean tree is a fractal generated by the following procedure:
Start with a unit square. Then, calling one of the sides its base (in the animation, the bottom side is the base):
- Attach a right triangle to the side opposite the base, with the hypotenuse coinciding with that side and with the sides in a $3\text - 4\text - 5$ ratio. Note that the smaller side of the triangle must be on the 'right' side with respect to the base (see animation).
- Attach a square to each leg of the right triangle, with one of its sides coinciding with that leg.
- Repeat this procedure for both squares, considering as their bases the sides touching the triangle.
The resulting figure, after an infinite number of iterations, is the Pythagorean tree.
It can be shown that there exists at least one rectangle, whose sides are parallel to the largest square of the Pythagorean tree, which encloses the Pythagorean tree completely.
Find the smallest area possible for such a bounding rectangle, and give your answer rounded to $10$ decimal places. | <p>
The <strong>Pythagorean tree</strong> is a fractal generated by the following procedure:
</p>
<p>
Start with a unit square. Then, calling one of the sides its base (in the animation, the bottom side is the base):
</p><ol><li> Attach a right triangle to the side opposite the base, with the hypotenuse coinciding with that side and with the sides in a $3\text - 4\text - 5$ ratio. Note that the smaller side of the triangle must be on the 'right' side with respect to the base (see animation).</li>
<li> Attach a square to each leg of the right triangle, with one of its sides coinciding with that leg.</li>
<li> Repeat this procedure for both squares, considering as their bases the sides touching the triangle.</li>
</ol>
The resulting figure, after an infinite number of iterations, is the Pythagorean tree.
<div align="center"><img src="resources/images/0395_pythagorean.gif?1678992056" alt="0395_pythagorean.gif"></div>
<p>
It can be shown that there exists at least one rectangle, whose sides are parallel to the largest square of the Pythagorean tree, which encloses the Pythagorean tree completely.
</p>
<p>
Find the smallest area possible for such a bounding rectangle, and give your answer rounded to $10$ decimal places.
</p> | https://projecteuler.net/problem=395 | 28.2453753155 |
396 | For any positive integer $n$, the $n$th weak Goodstein sequence $\{g_1, g_2, g_3, \dots\}$ is defined as:
- $g_1 = n$
- for $k \gt 1$, $g_k$ is obtained by writing $g_{k-1}$ in base $k$, interpreting it as a base $k + 1$ number, and subtracting $1$.
The sequence terminates when $g_k$ becomes $0$.
For example, the $6$th weak Goodstein sequence is $\{6, 11, 17, 25, \dots\}$:
- $g_1 = 6$.
- $g_2 = 11$ since $6 = 110_2$, $110_3 = 12$, and $12 - 1 = 11$.
- $g_3 = 17$ since $11 = 102_3$, $102_4 = 18$, and $18 - 1 = 17$.
- $g_4 = 25$ since $17 = 101_4$, $101_5 = 26$, and $26 - 1 = 25$.
and so on.
It can be shown that every weak Goodstein sequence terminates.
Let $G(n)$ be the number of nonzero elements in the $n$th weak Goodstein sequence.
It can be verified that $G(2) = 3$, $G(4) = 21$ and $G(6) = 381$.
It can also be verified that $\sum G(n) = 2517$ for $1 \le n \lt 8$.
Find the last $9$ digits of $\sum G(n)$ for $1 \le n \lt 16$. | <p>
For any positive integer $n$, the <strong>$n$th weak Goodstein sequence</strong> $\{g_1, g_2, g_3, \dots\}$ is defined as:
</p><ul><li> $g_1 = n$
</li><li> for $k \gt 1$, $g_k$ is obtained by writing $g_{k-1}$ in base $k$, interpreting it as a base $k + 1$ number, and subtracting $1$.
</li></ul>
The sequence terminates when $g_k$ becomes $0$.
<p>
For example, the $6$th weak Goodstein sequence is $\{6, 11, 17, 25, \dots\}$:
</p><ul><li> $g_1 = 6$.
</li><li> $g_2 = 11$ since $6 = 110_2$, $110_3 = 12$, and $12 - 1 = 11$.
</li><li> $g_3 = 17$ since $11 = 102_3$, $102_4 = 18$, and $18 - 1 = 17$.
</li><li> $g_4 = 25$ since $17 = 101_4$, $101_5 = 26$, and $26 - 1 = 25$.
</li></ul>
and so on.
<p>
It can be shown that every weak Goodstein sequence terminates.
</p>
<p>
Let $G(n)$ be the number of nonzero elements in the $n$th weak Goodstein sequence.<br>
It can be verified that $G(2) = 3$, $G(4) = 21$ and $G(6) = 381$.<br>
It can also be verified that $\sum G(n) = 2517$ for $1 \le n \lt 8$.
</p>
<p>
Find the last $9$ digits of $\sum G(n)$ for $1 \le n \lt 16$.
</p> | https://projecteuler.net/problem=396 | 173214653 |
397 | On the parabola $y = x^2/k$, three points $A(a, a^2/k)$, $B(b, b^2/k)$ and $C(c, c^2/k)$ are chosen.
Let $F(K, X)$ be the number of the integer quadruplets $(k, a, b, c)$ such that at least one angle of the triangle $ABC$ is $45$-degree, with $1 \le k \le K$ and $-X \le a \lt b \lt c \le X$.
For example, $F(1, 10) = 41$ and $F(10, 100) = 12492$.
Find $F(10^6, 10^9)$. | <p>
On the parabola $y = x^2/k$, three points $A(a, a^2/k)$, $B(b, b^2/k)$ and $C(c, c^2/k)$ are chosen.
</p>
<p>
Let $F(K, X)$ be the number of the integer quadruplets $(k, a, b, c)$ such that at least one angle of the triangle $ABC$ is $45$-degree, with $1 \le k \le K$ and $-X \le a \lt b \lt c \le X$.
</p>
<p>
For example, $F(1, 10) = 41$ and $F(10, 100) = 12492$.<br>
Find $F(10^6, 10^9)$.
</p> | https://projecteuler.net/problem=397 | 141630459461893728 |
398 | Inside a rope of length $n$, $n - 1$ points are placed with distance $1$ from each other and from the endpoints. Among these points, we choose $m - 1$ points at random and cut the rope at these points to create $m$ segments.
Let $E(n, m)$ be the expected length of the second-shortest segment.
For example, $E(3, 2) = 2$ and $E(8, 3) = 16/7$.
Note that if multiple segments have the same shortest length the length of the second-shortest segment is defined as the same as the shortest length.
Find $E(10^7, 100)$.
Give your answer rounded to $5$ decimal places behind the decimal point. | <p>
Inside a rope of length $n$, $n - 1$ points are placed with distance $1$ from each other and from the endpoints. Among these points, we choose $m - 1$ points at random and cut the rope at these points to create $m$ segments.
</p>
<p>
Let $E(n, m)$ be the expected length of the second-shortest segment.
For example, $E(3, 2) = 2$ and $E(8, 3) = 16/7$.
Note that if multiple segments have the same shortest length the length of the second-shortest segment is defined as the same as the shortest length.
</p>
<p>
Find $E(10^7, 100)$.
Give your answer rounded to $5$ decimal places behind the decimal point.
</p> | https://projecteuler.net/problem=398 | 2010.59096 |
399 | The first $15$ Fibonacci numbers are:
$1,1,2,3,5,8,13,21,34,55,89,144,233,377,610$.
It can be seen that $8$ and $144$ are not squarefree: $8$ is divisible by $4$ and $144$ is divisible by $4$ and by $9$.
So the first $13$ squarefree Fibonacci numbers are:
$1,1,2,3,5,13,21,34,55,89,233,377$ and $610$.
The $200$th squarefree Fibonacci number is:
$971183874599339129547649988289594072811608739584170445$.
The last sixteen digits of this number are: $1608739584170445$ and in scientific notation this number can be written as $9.7\mathrm e53$.
Find the $100\,000\,000$th squarefree Fibonacci number.
Give as your answer its last sixteen digits followed by a comma followed by the number in scientific notation (rounded to one digit after the decimal point).
For the $200$th squarefree number the answer would have been: 1608739584170445,9.7e53
Note:
For this problem, assume that for every prime $p$, the first fibonacci number divisible by $p$ is not divisible by $p^2$ (this is part of Wall's conjecture). This has been verified for primes $\le 3 \cdot 10^{15}$, but has not been proven in general.
If it happens that the conjecture is false, then the accepted answer to this problem isn't guaranteed to be the $100\,000\,000$th squarefree Fibonacci number, rather it represents only a lower bound for that number. | <p>
The first $15$ Fibonacci numbers are:<br>
$1,1,2,3,5,8,13,21,34,55,89,144,233,377,610$.<br>
It can be seen that $8$ and $144$ are not squarefree: $8$ is divisible by $4$ and $144$ is divisible by $4$ and by $9$.<br>
So the first $13$ squarefree Fibonacci numbers are:<br>
$1,1,2,3,5,13,21,34,55,89,233,377$ and $610$.
</p>
<p>
The $200$th squarefree Fibonacci number is:
$971183874599339129547649988289594072811608739584170445$.<br>
The last sixteen digits of this number are: $1608739584170445$ and in scientific notation this number can be written as $9.7\mathrm e53$.
</p>
<p>
Find the $100\,000\,000$th squarefree Fibonacci number.<br>
Give as your answer its last sixteen digits followed by a comma followed by the number in scientific notation (rounded to one digit after the decimal point).<br>
For the $200$th squarefree number the answer would have been: 1608739584170445,9.7e53
</p>
<p>
<font size="-1">
Note:<br>
For this problem, assume that for every prime $p$, the first fibonacci number divisible by $p$ is not divisible by $p^2$ (this is part of <strong>Wall's conjecture</strong>). This has been verified for primes $\le 3 \cdot 10^{15}$, but has not been proven in general.<br>
If it happens that the conjecture is false, then the accepted answer to this problem isn't guaranteed to be the $100\,000\,000$th squarefree Fibonacci number, rather it represents only a lower bound for that number.
</font>
</p> | https://projecteuler.net/problem=399 | 1508395636674243,6.5e27330467 |
400 | A Fibonacci tree is a binary tree recursively defined as:
- $T(0)$ is the empty tree.
- $T(1)$ is the binary tree with only one node.
- $T(k)$ consists of a root node that has $T(k-1)$ and $T(k-2)$ as children.
On such a tree two players play a take-away game. On each turn a player selects a node and removes that node along with the subtree rooted at that node.
The player who is forced to take the root node of the entire tree loses.
Here are the winning moves of the first player on the first turn for $T(k)$ from $k=1$ to $k=6$.
Let $f(k)$ be the number of winning moves of the first player (i.e. the moves for which the second player has no winning strategy) on the first turn of the game when this game is played on $T(k)$.
For example, $f(5) = 1$ and $f(10) = 17$.
Find $f(10000)$. Give the last $18$ digits of your answer. | <p>
A <b>Fibonacci tree</b> is a binary tree recursively defined as:</p><ul><li>$T(0)$ is the empty tree.
</li><li>$T(1)$ is the binary tree with only one node.
</li><li>$T(k)$ consists of a root node that has $T(k-1)$ and $T(k-2)$ as children.
</li></ul><p>
On such a tree two players play a take-away game. On each turn a player selects a node and removes that node along with the subtree rooted at that node.<br>
The player who is forced to take the root node of the entire tree loses.</p><p>
</p><p>
Here are the winning moves of the first player on the first turn for $T(k)$ from $k=1$ to $k=6$.
</p><p align="center"><img src="resources/images/0400_winning.png?1678992053" class="dark_img" alt="0400_winning.png"></p>
Let $f(k)$ be the number of winning moves of the first player (i.e. the moves for which the second player has no winning strategy) on the first turn of the game when this game is played on $T(k)$.
<p>
For example, $f(5) = 1$ and $f(10) = 17$.
</p>
<p>
Find $f(10000)$. Give the last $18$ digits of your answer.
</p> | https://projecteuler.net/problem=400 | 438505383468410633 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.