id int64 1 981 | problem stringlengths 97 5.29k | raw_html stringlengths 121 5.63k | url stringlengths 34 36 | answer stringlengths 1 29 |
|---|---|---|---|---|
501 | The eight divisors of $24$ are $1, 2, 3, 4, 6, 8, 12$ and $24$.
The ten numbers not exceeding $100$ having exactly eight divisors are $24, 30, 40, 42, 54, 56, 66, 70, 78$ and $88$.
Let $f(n)$ be the count of numbers not exceeding $n$ with exactly eight divisors.
You are given $f(100) = 10$, $f(1000) = 180$ and $f(10^6) = 224427$.
Find $f(10^{12})$. | <p>The eight divisors of $24$ are $1, 2, 3, 4, 6, 8, 12$ and $24$.
The ten numbers not exceeding $100$ having exactly eight divisors are $24, 30, 40, 42, 54, 56, 66, 70, 78$ and $88$.
Let $f(n)$ be the count of numbers not exceeding $n$ with exactly eight divisors.<br>
You are given $f(100) = 10$, $f(1000) = 180$ and $f(10^6) = 224427$.<br>
Find $f(10^{12})$.</p> | https://projecteuler.net/problem=501 | 197912312715 |
502 | We define a block to be a rectangle with a height of $1$ and an integer-valued length. Let a castle be a configuration of stacked blocks.
Given a game grid that is $w$ units wide and $h$ units tall, a castle is generated according to the following rules:
- Blocks can be placed on top of other blocks as long as nothing sticks out past the edges or hangs out over open space.
- All blocks are aligned/snapped to the grid.
- Any two neighboring blocks on the same row have at least one unit of space between them.
- The bottom row is occupied by a block of length $w$.
- The maximum achieved height of the entire castle is exactly $h$.
- The castle is made from an even number of blocks.
The following is a sample castle for $w=8$ and $h=5$:
Let $F(w,h)$ represent the number of valid castles, given grid parameters $w$ and $h$.
For example, $F(4,2) = 10$, $F(13,10) = 3729050610636$, $F(10,13) = 37959702514$, and $F(100,100) \bmod 1\,000\,000\,007 = 841913936$.
Find $(F(10^{12},100) + F(10000,10000) + F(100,10^{12})) \bmod 1\,000\,000\,007$. | <p>We define a <dfn>block</dfn> to be a rectangle with a height of $1$ and an integer-valued length. Let a <dfn>castle</dfn> be a configuration of stacked blocks.</p>
<p>Given a game grid that is $w$ units wide and $h$ units tall, a castle is generated according to the following rules:</p>
<ol><li>Blocks can be placed on top of other blocks as long as nothing sticks out past the edges or hangs out over open space.</li>
<li>All blocks are aligned/snapped to the grid.</li>
<li>Any two neighboring blocks on the same row have at least one unit of space between them.</li>
<li>The bottom row is occupied by a block of length $w$.</li>
<li>The maximum achieved height of the entire castle is exactly $h$.</li>
<li>The castle is made from an even number of blocks.</li>
</ol><p>The following is a sample castle for $w=8$ and $h=5$:</p>
<p align="center"><img src="resources/images/0502_castles.png?1678992053" alt="0502_castles.png"></p>
<p>Let $F(w,h)$ represent the number of valid castles, given grid parameters $w$ and $h$.</p>
<p>For example, $F(4,2) = 10$, $F(13,10) = 3729050610636$, $F(10,13) = 37959702514$, and $F(100,100) \bmod 1\,000\,000\,007 = 841913936$.</p>
<p>Find $(F(10^{12},100) + F(10000,10000) + F(100,10^{12})) \bmod 1\,000\,000\,007$.</p> | https://projecteuler.net/problem=502 | 749485217 |
503 | Alice is playing a game with $n$ cards numbered $1$ to $n$.
A game consists of iterations of the following steps.
(1) Alice picks one of the cards at random.
(2) Alice cannot see the number on it. Instead, Bob, one of her friends, sees the number and tells Alice how many previously-seen numbers are bigger than the number which he is seeing.
(3) Alice can end or continue the game. If she decides to end, the number becomes her score. If she decides to continue, the card is removed from the game and she returns to (1). If there is no card left, she is forced to end the game.
Let $F(n)$ be Alice's expected score if she takes the optimized strategy to minimize her score.
For example, $F(3) = 5/3$. At the first iteration, she should continue the game. At the second iteration, she should end the game if Bob says that one previously-seen number is bigger than the number which he is seeing, otherwise she should continue the game.
We can also verify that $F(4) = 15/8$ and $F(10) \approx 2.5579365079$.
Find $F(10^6)$. Give your answer rounded to $10$ decimal places behind the decimal point. | <p>Alice is playing a game with $n$ cards numbered $1$ to $n$.</p>
<p>A game consists of iterations of the following steps.<br>
(1) Alice picks one of the cards at random.<br>
(2) Alice cannot see the number on it. Instead, Bob, one of her friends, sees the number and tells Alice how many previously-seen numbers are bigger than the number which he is seeing.<br>
(3) Alice can end or continue the game. If she decides to end, the number becomes her score. If she decides to continue, the card is removed from the game and she returns to (1). If there is no card left, she is forced to end the game.<br></p>
<p>Let $F(n)$ be Alice's expected score if she takes the optimized strategy to <b>minimize</b> her score.</p>
<p>For example, $F(3) = 5/3$. At the first iteration, she should continue the game. At the second iteration, she should end the game if Bob says that one previously-seen number is bigger than the number which he is seeing, otherwise she should continue the game.</p>
<p>We can also verify that $F(4) = 15/8$ and $F(10) \approx 2.5579365079$.</p>
<p>Find $F(10^6)$. Give your answer rounded to $10$ decimal places behind the decimal point.</p> | https://projecteuler.net/problem=503 | 3.8694550145 |
504 | Let $ABCD$ be a quadrilateral whose vertices are lattice points lying on the coordinate axes as follows:
$A(a, 0)$, $B(0, b)$, $C(-c, 0)$, $D(0, -d)$, where $1 \le a, b, c, d \le m$ and $a, b, c, d, m$ are integers.
It can be shown that for $m = 4$ there are exactly $256$ valid ways to construct $ABCD$. Of these $256$ quadrilaterals, $42$ of them strictly contain a square number of lattice points.
How many quadrilaterals $ABCD$ strictly contain a square number of lattice points for $m = 100$? | <p>Let $ABCD$ be a quadrilateral whose vertices are lattice points lying on the coordinate axes as follows:</p>
<p>$A(a, 0)$, $B(0, b)$, $C(-c, 0)$, $D(0, -d)$, where $1 \le a, b, c, d \le m$ and $a, b, c, d, m$ are integers.</p>
<p>It can be shown that for $m = 4$ there are exactly $256$ valid ways to construct $ABCD$. Of these $256$ quadrilaterals, $42$ of them <u>strictly</u> contain a square number of lattice points.</p>
<p>How many quadrilaterals $ABCD$ strictly contain a square number of lattice points for $m = 100$?</p> | https://projecteuler.net/problem=504 | 694687 |
505 | Let:
$\begin{array}{ll} x(0)&=0 \\ x(1)&=1 \\ x(2k)&=(3x(k)+2x(\lfloor \frac k 2 \rfloor)) \text{ mod } 2^{60} \text{ for } k \ge 1 \text {, where } \lfloor \text { } \rfloor \text { is the floor function} \\ x(2k+1)&=(2x(k)+3x(\lfloor \frac k 2 \rfloor)) \text{ mod } 2^{60} \text{ for } k \ge 1 \\ y_n(k)&=\left\{{\begin{array}{lc} x(k) && \text{if } k \ge n \\ 2^{60} - 1 - max(y_n(2k),y_n(2k+1)) && \text{if } k < n \end{array}} \right. \\ A(n)&=y_n(1) \end{array}$
You are given:
$\begin{array}{ll} x(2)&=3 \\ x(3)&=2 \\ x(4)&=11 \\ y_4(4)&=11 \\ y_4(3)&=2^{60}-9\\ y_4(2)&=2^{60}-12 \\ y_4(1)&=A(4)=8 \\ A(10)&=2^{60}-34\\ A(10^3)&=101881 \end{array}$
Find $A(10^{12})$. | <p>Let:</p>
<p style="margin-left:32px;">$\begin{array}{ll} x(0)&=0 \\ x(1)&=1 \\ x(2k)&=(3x(k)+2x(\lfloor \frac k 2 \rfloor)) \text{ mod } 2^{60} \text{ for } k \ge 1 \text {, where } \lfloor \text { } \rfloor \text { is the floor function} \\ x(2k+1)&=(2x(k)+3x(\lfloor \frac k 2 \rfloor)) \text{ mod } 2^{60} \text{ for } k \ge 1 \\ y_n(k)&=\left\{{\begin{array}{lc} x(k) && \text{if } k \ge n \\ 2^{60} - 1 - max(y_n(2k),y_n(2k+1)) && \text{if } k < n \end{array}} \right. \\ A(n)&=y_n(1) \end{array}$</p>
<p>You are given:</p>
<p style="margin-left:32px;">$\begin{array}{ll} x(2)&=3 \\ x(3)&=2 \\ x(4)&=11 \\ y_4(4)&=11 \\ y_4(3)&=2^{60}-9\\ y_4(2)&=2^{60}-12 \\ y_4(1)&=A(4)=8 \\ A(10)&=2^{60}-34\\ A(10^3)&=101881 \end{array}$</p>
Find $A(10^{12})$. | https://projecteuler.net/problem=505 | 714591308667615832 |
506 | Consider the infinite repeating sequence of digits:
1234321234321234321...
Amazingly, you can break this sequence of digits into a sequence of integers such that the sum of the digits in the $n$-th value is $n$.
The sequence goes as follows:
1, 2, 3, 4, 32, 123, 43, 2123, 432, 1234, 32123, ...
Let $v_n$ be the $n$-th value in this sequence. For example, $v_2=2$, $v_5=32$ and $v_{11}=32123$.
Let $S(n)$ be $v_1+v_2+\cdots+v_n$. For example, $S(11)=36120$, and $S(1000)\bmod 123454321=18232686$.
Find $S(10^{14})\bmod 123454321$. | <p>Consider the infinite repeating sequence of digits:<br>
1234321234321234321...</p>
<p>Amazingly, you can break this sequence of digits into a sequence of integers such that the sum of the digits in the $n$-th value is $n$.</p>
<p>The sequence goes as follows:<br>
1, 2, 3, 4, 32, 123, 43, 2123, 432, 1234, 32123, ...</p>
<p>Let $v_n$ be the $n$-th value in this sequence. For example, $v_2=2$, $v_5=32$ and $v_{11}=32123$.</p>
<p>Let $S(n)$ be $v_1+v_2+\cdots+v_n$. For example, $S(11)=36120$, and $S(1000)\bmod 123454321=18232686$.</p>
<p>Find $S(10^{14})\bmod 123454321$.</p> | https://projecteuler.net/problem=506 | 18934502 |
507 | Let $t_n$ be the tribonacci numbers defined as:
$t_0 = t_1 = 0$;
$t_2 = 1$;
$t_n = t_{n-1} + t_{n-2} + t_{n-3}$ for $n \ge 3$
and let $r_n = t_n \text{ mod } 10^7$.
For each pair of Vectors $V_n=(v_1,v_2,v_3)$ and $W_n=(w_1,w_2,w_3)$ with $v_1=r_{12n-11}-r_{12n-10}, v_2=r_{12n-9}+r_{12n-8}, v_3=r_{12n-7} \cdot r_{12n-6}$ and
$w_1=r_{12n-5}-r_{12n-4}, w_2=r_{12n-3}+r_{12n-2}, w_3=r_{12n-1} \cdot r_{12n}$
we define $S(n)$ as the minimal value of the manhattan length of the vector $D=k \cdot V_n+l \cdot W_n$ measured as $|k \cdot v_1+l \cdot w_1|+|k \cdot v_2+l \cdot w_2|+|k \cdot v_3+l \cdot w_3|$
for any integers $k$ and $l$ with $(k,l)\neq (0,0)$.
The first vector pair is $(-1, 3, 28)$, $(-11, 125, 40826)$.
You are given that $S(1)=32$ and $\sum_{n=1}^{10} S(n)=130762273722$.
Find $\sum_{n=1}^{20000000} S(n)$. | <p>
Let $t_n$ be the <b>tribonacci numbers</b> defined as:<br>
$t_0 = t_1 = 0$;<br>
$t_2 = 1$;<br>
$t_n = t_{n-1} + t_{n-2} + t_{n-3}$ for $n \ge 3$<br>
and let $r_n = t_n \text{ mod } 10^7$.
</p>
<p>
For each pair of Vectors $V_n=(v_1,v_2,v_3)$ and $W_n=(w_1,w_2,w_3)$ with $v_1=r_{12n-11}-r_{12n-10}, v_2=r_{12n-9}+r_{12n-8}, v_3=r_{12n-7} \cdot r_{12n-6}$ and <br> $w_1=r_{12n-5}-r_{12n-4}, w_2=r_{12n-3}+r_{12n-2}, w_3=r_{12n-1} \cdot r_{12n}$
<br>
we define $S(n)$ as the minimal value of the manhattan length of the vector $D=k \cdot V_n+l \cdot W_n$ measured as $|k \cdot v_1+l \cdot w_1|+|k \cdot v_2+l \cdot w_2|+|k \cdot v_3+l \cdot w_3|$
for any integers $k$ and $l$ with $(k,l)\neq (0,0)$.
</p><p>
The first vector pair is $(-1, 3, 28)$, $(-11, 125, 40826)$.<br>
You are given that $S(1)=32$ and $\sum_{n=1}^{10} S(n)=130762273722$.
</p>
<p>
Find $\sum_{n=1}^{20000000} S(n)$.
</p> | https://projecteuler.net/problem=507 | 316558047002627270 |
508 | Consider the Gaussian integer $i-1$. A base $i-1$ representation of a Gaussian integer $a+bi$ is a finite sequence of digits $d_{n - 1}d_{n - 2}\cdots d_1 d_0$ such that:
- $a+bi = d_{n - 1}(i - 1)^{n - 1} + d_{n - 2}(i - 1)^{n - 2} + \cdots + d_1(i - 1) + d_0$
- Each $d_k$ is in $\{0,1\}$
- There are no leading zeroes, i.e. $d_{n-1} \ne 0$, unless $a+bi$ is itself $0$
Here are base $i-1$ representations of a few Gaussian integers:
$11+24i \to 111010110001101$
$24-11i \to 110010110011$
$8+0i \to 111000000$
$-5+0i \to 11001101$
$0+0i \to 0$
Remarkably, every Gaussian integer has a unique base $i-1$ representation!
Define $f(a + bi)$ as the number of $1$s in the unique base $i-1$ representation of $a + bi$. For example, $f(11+24i) = 9$ and $f(24-11i) = 7$.
Define $B(L)$ as the sum of $f(a + bi)$ for all integers $a, b$ such that $|a| \le L$ and $|b| \le L$. For example, $B(500) = 10795060$.
Find $B(10^{15}) \bmod 1\,000\,000\,007$. | <p>Consider the Gaussian integer $i-1$. A <strong>base $i-1$ representation</strong> of a Gaussian integer $a+bi$ is a finite sequence of digits $d_{n - 1}d_{n - 2}\cdots d_1 d_0$ such that:</p>
<ul><li>$a+bi = d_{n - 1}(i - 1)^{n - 1} + d_{n - 2}(i - 1)^{n - 2} + \cdots + d_1(i - 1) + d_0$</li>
<li>Each $d_k$ is in $\{0,1\}$</li>
<li>There are no leading zeroes, i.e. $d_{n-1} \ne 0$, unless $a+bi$ is itself $0$</li>
</ul><p>Here are base $i-1$ representations of a few Gaussian integers:<br><br>
$11+24i \to 111010110001101$<br>
$24-11i \to 110010110011$<br>
$8+0i \to 111000000$<br>
$-5+0i \to 11001101$<br>
$0+0i \to 0$</p>
<p>
Remarkably, every Gaussian integer has a unique base $i-1$ representation!</p>
<p>
Define $f(a + bi)$ as the number of $1$s in the unique base $i-1$ representation of $a + bi$. For example, $f(11+24i) = 9$ and $f(24-11i) = 7$.</p>
<p>
Define $B(L)$ as the sum of $f(a + bi)$ for all integers $a, b$ such that $|a| \le L$ and $|b| \le L$. For example, $B(500) = 10795060$.</p>
<p>
Find $B(10^{15}) \bmod 1\,000\,000\,007$.</p> | https://projecteuler.net/problem=508 | 891874596 |
509 | Anton and Bertrand love to play three pile Nim.
However, after a lot of games of Nim they got bored and changed the rules somewhat.
They may only take a number of stones from a pile that is a proper divisora proper divisor of $n$ is a divisor of $n$ smaller than $n$ of the number of stones present in the pile.
E.g. if a pile at a certain moment contains $24$ stones they may take only $1,2,3,4,6,8$ or $12$ stones from that pile.
So if a pile contains one stone they can't take the last stone from it as $1$ isn't a proper divisor of $1$.
The first player that can't make a valid move loses the game.
Of course both Anton and Bertrand play optimally.
The triple $(a, b, c)$ indicates the number of stones in the three piles.
Let $S(n)$ be the number of winning positions for the next player for $1 \le a, b, c \le n$.
$S(10) = 692$ and $S(100) = 735494$.
Find $S(123456787654321)$ modulo $1234567890$. | <p>
Anton and Bertrand love to play three pile Nim.<br>
However, after a lot of games of Nim they got bored and changed the rules somewhat.<br>
They may only take a number of stones from a pile that is a <dfn class="tooltip">proper divisor<span class="tooltiptext">a proper divisor of $n$ is a divisor of $n$ smaller than $n$</span></dfn> of the number of stones present in the pile.<br> E.g. if a pile at a certain moment contains $24$ stones they may take only $1,2,3,4,6,8$ or $12$ stones from that pile.<br>
So if a pile contains one stone they can't take the last stone from it as $1$ isn't a proper divisor of $1$.<br>
The first player that can't make a valid move loses the game.<br>
Of course both Anton and Bertrand play optimally.</p>
<p>
The triple $(a, b, c)$ indicates the number of stones in the three piles.<br>
Let $S(n)$ be the number of winning positions for the next player for $1 \le a, b, c \le n$.<br>$S(10) = 692$ and $S(100) = 735494$.</p>
<p>
Find $S(123456787654321)$ modulo $1234567890$.
</p> | https://projecteuler.net/problem=509 | 151725678 |
510 | Circles $A$ and $B$ are tangent to each other and to line $L$ at three distinct points.
Circle $C$ is inside the space between $A$, $B$ and $L$, and tangent to all three.
Let $r_A$, $r_B$ and $r_C$ be the radii of $A$, $B$ and $C$ respectively.
Let $S(n) = \sum r_A + r_B + r_C$, for $0 \lt r_A \le r_B \le n$ where $r_A$, $r_B$ and $r_C$ are integers.
The only solution for $0 \lt r_A \le r_B \le 5$ is $r_A = 4$, $r_B = 4$ and $r_C = 1$, so $S(5) = 4 + 4 + 1 = 9$.
You are also given $S(100) = 3072$.
Find $S(10^9)$. | <p>Circles $A$ and $B$ are tangent to each other and to line $L$ at three distinct points.<br>
Circle $C$ is inside the space between $A$, $B$ and $L$, and tangent to all three.<br>
Let $r_A$, $r_B$ and $r_C$ be the radii of $A$, $B$ and $C$ respectively.<br></p><div align="center"><img src="resources/images/0510_tangent_circles.png?1678992053" alt="0510_tangent_circles.png"></div>
<p>Let $S(n) = \sum r_A + r_B + r_C$, for $0 \lt r_A \le r_B \le n$ where $r_A$, $r_B$ and $r_C$ are integers.
The only solution for $0 \lt r_A \le r_B \le 5$ is $r_A = 4$, $r_B = 4$ and $r_C = 1$, so $S(5) = 4 + 4 + 1 = 9$.
You are also given $S(100) = 3072$.</p>
<p>Find $S(10^9)$.</p> | https://projecteuler.net/problem=510 | 315306518862563689 |
511 | Let $Seq(n,k)$ be the number of positive-integer sequences $\{a_i\}_{1 \le i \le n}$ of length $n$ such that:
- $n$ is divisible by $a_i$ for $1 \le i \le n$, and
- $n + a_1 + a_2 + \cdots + a_n$ is divisible by $k$.
Examples:
$Seq(3,4) = 4$, and the $4$ sequences are:
$\{1, 1, 3\}$
$\{1, 3, 1\}$
$\{3, 1, 1\}$
$\{3, 3, 3\}$
$Seq(4,11) = 8$, and the $8$ sequences are:
$\{1, 1, 1, 4\}$
$\{1, 1, 4, 1\}$
$\{1, 4, 1, 1\}$
$\{4, 1, 1, 1\}$
$\{2, 2, 2, 1\}$
$\{2, 2, 1, 2\}$
$\{2, 1, 2, 2\}$
$\{1, 2, 2, 2\}$
The last nine digits of $Seq(1111,24)$ are $840643584$.
Find the last nine digits of $Seq(1234567898765,4321)$. | <p>Let $Seq(n,k)$ be the number of positive-integer sequences $\{a_i\}_{1 \le i \le n}$ of length $n$ such that:</p>
<ul style="list-style-type:disc;"><li>$n$ is divisible by $a_i$ for $1 \le i \le n$, and</li>
<li>$n + a_1 + a_2 + \cdots + a_n$ is divisible by $k$.</li>
</ul><p>Examples:</p>
<p>$Seq(3,4) = 4$, and the $4$ sequences are:<br>
$\{1, 1, 3\}$<br>
$\{1, 3, 1\}$<br>
$\{3, 1, 1\}$<br>
$\{3, 3, 3\}$</p>
<p>$Seq(4,11) = 8$, and the $8$ sequences are:<br>
$\{1, 1, 1, 4\}$<br>
$\{1, 1, 4, 1\}$<br>
$\{1, 4, 1, 1\}$<br>
$\{4, 1, 1, 1\}$<br>
$\{2, 2, 2, 1\}$<br>
$\{2, 2, 1, 2\}$<br>
$\{2, 1, 2, 2\}$<br>
$\{1, 2, 2, 2\}$</p>
<p>The last nine digits of $Seq(1111,24)$ are $840643584$.</p>
<p>Find the last nine digits of $Seq(1234567898765,4321)$.</p> | https://projecteuler.net/problem=511 | 935247012 |
512 | Let $\varphi(n)$ be Euler's totient function.
Let $f(n)=(\sum_{i=1}^{n}\varphi(n^i)) \bmod (n+1)$.
Let $g(n)=\sum_{i=1}^{n} f(i)$.
$g(100)=2007$.
Find $g(5 \times 10^8)$. | <p>Let $\varphi(n)$ be Euler's totient function.</p><p>
Let $f(n)=(\sum_{i=1}^{n}\varphi(n^i)) \bmod (n+1)$.</p><p>
Let $g(n)=\sum_{i=1}^{n} f(i)$.</p><p>
$g(100)=2007$.
</p>
<p>
Find $g(5 \times 10^8)$.
</p> | https://projecteuler.net/problem=512 | 50660591862310323 |
513 | $ABC$ is an integral sided triangle with sides $a \le b \le c$.
$m_C$ is the median connecting $C$ and the midpoint of $AB$.
$F(n)$ is the number of such triangles with $c \le n$ for which $m_C$ has integral length as well.
$F(10)=3$ and $F(50)=165$.
Find $F(100000)$. | <p>
$ABC$ is an integral sided triangle with sides $a \le b \le c$.<br>
$m_C$ is the median connecting $C$ and the midpoint of $AB$. <br>
$F(n)$ is the number of such triangles with $c \le n$ for which $m_C$ has integral length as well.<br>
$F(10)=3$ and $F(50)=165$.</p>
<p>
Find $F(100000)$.
</p> | https://projecteuler.net/problem=513 | 2925619196 |
514 | A geoboard (of order $N$) is a square board with equally-spaced pins protruding from the surface, representing an integer point lattice for coordinates $0 \le x, y \le N$.
John begins with a pinless geoboard. Each position on the board is a hole that can be filled with a pin. John decides to generate a random integer between $1$ and $N+1$ (inclusive) for each hole in the geoboard. If the random integer is equal to $1$ for a given hole, then a pin is placed in that hole.
After John is finished generating numbers for all $(N+1)^2$ holes and placing any/all corresponding pins, he wraps a tight rubberband around the entire group of pins protruding from the board. Let $S$ represent the shape that is formed. $S$ can also be defined as the smallest convex shape that contains all the pins.
The above image depicts a sample layout for $N = 4$. The green markers indicate positions where pins have been placed, and the blue lines collectively represent the rubberband. For this particular arrangement, $S$ has an area of $6$. If there are fewer than three pins on the board (or if all pins are collinear), $S$ can be assumed to have zero area.
Let $E(N)$ be the expected area of $S$ given a geoboard of order $N$. For example, $E(1) = 0.18750$, $E(2) = 0.94335$, and $E(10) = 55.03013$ when rounded to five decimal places each.
Calculate $E(100)$ rounded to five decimal places. | <p>A <strong>geoboard</strong> (of order $N$) is a square board with equally-spaced pins protruding from the surface, representing an integer point lattice for coordinates $0 \le x, y \le N$.</p>
<p>John begins with a pinless geoboard. Each position on the board is a hole that can be filled with a pin. John decides to generate a random integer between $1$ and $N+1$ (inclusive) for each hole in the geoboard. If the random integer is equal to $1$ for a given hole, then a pin is placed in that hole.</p>
<p>After John is finished generating numbers for all $(N+1)^2$ holes and placing any/all corresponding pins, he wraps a tight rubberband around the entire group of pins protruding from the board. Let $S$ represent the shape that is formed. $S$ can also be defined as the smallest convex shape that contains all the pins.</p>
<div align="center"><img src="resources/images/0514_geoboard.png?1678992053" alt="0514_geoboard.png"></div>
<p>The above image depicts a sample layout for $N = 4$. The green markers indicate positions where pins have been placed, and the blue lines collectively represent the rubberband. For this particular arrangement, $S$ has an area of $6$. If there are fewer than three pins on the board (or if all pins are collinear), $S$ can be assumed to have zero area.</p>
<p>Let $E(N)$ be the expected area of $S$ given a geoboard of order $N$. For example, $E(1) = 0.18750$, $E(2) = 0.94335$, and $E(10) = 55.03013$ when rounded to five decimal places each.</p>
<p>Calculate $E(100)$ rounded to five decimal places.</p> | https://projecteuler.net/problem=514 | 8986.86698 |
515 | Let $d(p, n, 0)$ be the multiplicative inverse of $n$ modulo prime $p$, defined as $n \times d(p, n, 0) = 1 \bmod p$.
Let $d(p, n, k) = \sum_{i = 1}^n d(p, i, k - 1)$ for $k \ge 1$.
Let $D(a, b, k) = \sum (d(p, p-1, k) \bmod p)$ for all primes $a \le p \lt a + b$.
You are given:
- $D(101,1,10) = 45$
- $D(10^3,10^2,10^2) = 8334$
- $D(10^6,10^3,10^3) = 38162302$
Find $D(10^9,10^5,10^5)$. | <p>Let $d(p, n, 0)$ be the multiplicative inverse of $n$ modulo prime $p$, defined as $n \times d(p, n, 0) = 1 \bmod p$.<br>
Let $d(p, n, k) = \sum_{i = 1}^n d(p, i, k - 1)$ for $k \ge 1$.<br>
Let $D(a, b, k) = \sum (d(p, p-1, k) \bmod p)$ for all primes $a \le p \lt a + b$.</p>
<p>You are given:</p>
<ul><li>$D(101,1,10) = 45$</li>
<li>$D(10^3,10^2,10^2) = 8334$</li>
<li>$D(10^6,10^3,10^3) = 38162302$</li></ul><p>Find $D(10^9,10^5,10^5)$.</p> | https://projecteuler.net/problem=515 | 2422639000800 |
516 | $5$-smooth numbers are numbers whose largest prime factor doesn't exceed $5$.
$5$-smooth numbers are also called Hamming numbers.
Let $S(L)$ be the sum of the numbers $n$ not exceeding $L$ such that Euler's totient function $\phi(n)$ is a Hamming number.
$S(100)=3728$.
Find $S(10^{12})$. Give your answer modulo $2^{32}$. | <p>
$5$-smooth numbers are numbers whose largest prime factor doesn't exceed $5$.<br>
$5$-smooth numbers are also called Hamming numbers.<br>
Let $S(L)$ be the sum of the numbers $n$ not exceeding $L$ such that Euler's totient function $\phi(n)$ is a Hamming number.<br>
$S(100)=3728$.
</p>
<p>
Find $S(10^{12})$. Give your answer modulo $2^{32}$.
</p> | https://projecteuler.net/problem=516 | 939087315 |
517 | For every real number $a \gt 1$ is given the sequence $g_a$ by:
$g_{a}(x)=1$ for $x \lt a$
$g_{a}(x)=g_{a}(x-1)+g_a(x-a)$ for $x \ge a$
$G(n)=g_{\sqrt {n}}(n)$
$G(90)=7564511$.
Find $\sum G(p)$ for $p$ prime and $10000000 \lt p \lt 10010000$
Give your answer modulo $1000000007$. | <p>
For every real number $a \gt 1$ is given the sequence $g_a$ by:<br>
$g_{a}(x)=1$ for $x \lt a$<br>
$g_{a}(x)=g_{a}(x-1)+g_a(x-a)$ for $x \ge a$<br>
$G(n)=g_{\sqrt {n}}(n)$<br>
$G(90)=7564511$.</p>
<p>
Find $\sum G(p)$ for $p$ prime and $10000000 \lt p \lt 10010000$<br>
Give your answer modulo $1000000007$.
</p> | https://projecteuler.net/problem=517 | 581468882 |
518 | Let $S(n) = \sum a + b + c$ over all triples $(a, b, c)$ such that:
- $a$, $b$ and $c$ are prime numbers.
- $a \lt b \lt c \lt n$.
- $a+1$, $b+1$, and $c+1$ form a geometric sequence.
For example, $S(100) = 1035$ with the following triples:
$(2, 5, 11)$, $(2, 11, 47)$, $(5, 11, 23)$, $(5, 17, 53)$, $(7, 11, 17)$, $(7, 23, 71)$, $(11, 23, 47)$, $(17, 23, 31)$, $(17, 41, 97)$, $(31, 47, 71)$, $(71, 83, 97)$
Find $S(10^8)$. | <p>Let $S(n) = \sum a + b + c$ over all triples $(a, b, c)$ such that:</p>
<ul style="list-style-type:disc;"><li>$a$, $b$ and $c$ are prime numbers.</li>
<li>$a \lt b \lt c \lt n$.</li>
<li>$a+1$, $b+1$, and $c+1$ form a <strong>geometric sequence</strong>.</li>
</ul><p>For example, $S(100) = 1035$ with the following triples: </p>
<p>$(2, 5, 11)$, $(2, 11, 47)$, $(5, 11, 23)$, $(5, 17, 53)$, $(7, 11, 17)$, $(7, 23, 71)$, $(11, 23, 47)$, $(17, 23, 31)$, $(17, 41, 97)$, $(31, 47, 71)$, $(71, 83, 97)$</p>
<p>Find $S(10^8)$.</p> | https://projecteuler.net/problem=518 | 100315739184392 |
519 | An arrangement of coins in one or more rows with the bottom row being a block without gaps and every coin in a higher row touching exactly two coins in the row below is called a fountain of coins. Let $f(n)$ be the number of possible fountains with $n$ coins. For $4$ coins there are three possible arrangements:
Therefore $f(4) = 3$ while $f(10) = 78$.
Let $T(n)$ be the number of all possible colourings with three colours for all $f(n)$ different fountains with $n$ coins, given the condition that no two touching coins have the same colour. Below you see the possible colourings for one of the three valid fountains for $4$ coins:
You are given that $T(4) = 48$ and $T(10) = 17760$.
Find the last $9$ digits of $T(20000)$. | <p>An arrangement of coins in one or more rows with the bottom row being a block without gaps and every coin in a higher row touching exactly two coins in the row below is called a <dfn>fountain</dfn> of coins. Let $f(n)$ be the number of possible fountains with $n$ coins. For $4$ coins there are three possible arrangements:</p>
<div align="center"><img src="resources/images/0519_coin_fountain.png?1678992053" alt="0519_coin_fountain.png"></div>
<p>Therefore $f(4) = 3$ while $f(10) = 78$.</p>
<p>Let $T(n)$ be the number of all possible colourings with three colours for all $f(n)$ different fountains with $n$ coins, given the condition that no two touching coins have the same colour. Below you see the possible colourings for one of the three valid fountains for $4$ coins:</p>
<div align="center"><img src="resources/images/0519_tricolored_coin_fountain.png?1678992053" alt="0519_tricolored_coin_fountain.png"></div>
<p>You are given that $T(4) = 48$ and $T(10) = 17760$.</p>
<p>Find the last $9$ digits of $T(20000)$.</p> | https://projecteuler.net/problem=519 | 804739330 |
520 | We define a simber to be a positive integer in which any odd digit, if present, occurs an odd number of times, and any even digit, if present, occurs an even number of times.
For example, $141221242$ is a $9$-digit simber because it has three $1$'s, four $2$'s and two $4$'s.
Let $Q(n)$ be the count of all simbers with at most $n$ digits.
You are given $Q(7) = 287975$ and $Q(100) \bmod 1\,000\,000\,123 = 123864868$.
Find $(\sum_{1 \le u \le 39} Q(2^u)) \bmod 1\,000\,000\,123$. | <p>We define a <dfn>simber</dfn> to be a positive integer in which any odd digit, if present, occurs an odd number of times, and any even digit, if present, occurs an even number of times.</p>
<p>For example, $141221242$ is a $9$-digit simber because it has three $1$'s, four $2$'s and two $4$'s. </p>
<p>Let $Q(n)$ be the count of all simbers with at most $n$ digits.</p>
<p>You are given $Q(7) = 287975$ and $Q(100) \bmod 1\,000\,000\,123 = 123864868$.</p>
<p>Find $(\sum_{1 \le u \le 39} Q(2^u)) \bmod 1\,000\,000\,123$.</p> | https://projecteuler.net/problem=520 | 238413705 |
521 | Let $\operatorname{smpf}(n)$ be the smallest prime factor of $n$.
$\operatorname{smpf}(91)=7$ because $91=7\times 13$ and $\operatorname{smpf}(45)=3$ because $45=3\times 3\times 5$.
Let $S(n)$ be the sum of $\operatorname{smpf}(i)$ for $2 \le i \le n$.
E.g. $S(100)=1257$.
Find $S(10^{12}) \bmod 10^9$. | <p>
Let $\operatorname{smpf}(n)$ be the smallest prime factor of $n$.<br>
$\operatorname{smpf}(91)=7$ because $91=7\times 13$ and $\operatorname{smpf}(45)=3$ because $45=3\times 3\times 5$.<br>
Let $S(n)$ be the sum of $\operatorname{smpf}(i)$ for $2 \le i \le n$.<br>
E.g. $S(100)=1257$.
</p>
<p>
Find $S(10^{12}) \bmod 10^9$.
</p> | https://projecteuler.net/problem=521 | 44389811 |
522 | Despite the popularity of Hilbert's infinite hotel, Hilbert decided to try managing extremely large finite hotels, instead.
To cut costs, Hilbert wished to power the new hotel with his own special generator. Each floor would send power to the floor above it, with the top floor sending power back down to the bottom floor. That way, Hilbert could have the generator placed on any given floor (as he likes having the option) and have electricity flow freely throughout the entire hotel.
Unfortunately, the contractors misinterpreted the schematics when they built the hotel. They informed Hilbert that each floor sends power to another floor at random, instead. This may compromise Hilbert's freedom to have the generator placed anywhere, since blackouts could occur on certain floors.
For example, consider a sample flow diagram for a three-story hotel:
If the generator were placed on the first floor, then every floor would receive power. But if it were placed on the second or third floors instead, then there would be a blackout on the first floor. Note that while a given floor can receive power from many other floors at once, it can only send power to one other floor.
To resolve the blackout concerns, Hilbert decided to have a minimal number of floors rewired. To rewire a floor is to change the floor it sends power to. In the sample diagram above, all possible blackouts can be avoided by rewiring the second floor to send power to the first floor instead of the third floor.
Let $F(n)$ be the sum of the minimum number of floor rewirings needed over all possible power-flow arrangements in a hotel of $n$ floors. For example, $F(3) = 6$, $F(8) = 16276736$, and $F(100) \bmod 135707531 = 84326147$.
Find $F(12344321) \bmod 135707531$. | <p>Despite the popularity of Hilbert's infinite hotel, Hilbert decided to try managing extremely large finite hotels, instead.</p>
<p>To cut costs, Hilbert wished to power the new hotel with his own special generator. Each floor would send power to the floor above it, with the top floor sending power back down to the bottom floor. That way, Hilbert could have the generator placed on any given floor (as he likes having the option) and have electricity flow freely throughout the entire hotel.</p>
<p>Unfortunately, the contractors misinterpreted the schematics when they built the hotel. They informed Hilbert that each floor sends power to another floor at random, instead. This may compromise Hilbert's freedom to have the generator placed anywhere, since blackouts could occur on certain floors.</p>
<p>For example, consider a sample flow diagram for a three-story hotel:</p>
<p align="center"><img src="resources/images/0522_hilberts_blackout.png?1678992053" alt="0522_hilberts_blackout.png"></p>
<p>If the generator were placed on the first floor, then every floor would receive power. But if it were placed on the second or third floors instead, then there would be a blackout on the first floor. Note that while a given floor can <i>receive</i> power from many other floors at once, it can only <i>send</i> power to one other floor.</p>
<p>To resolve the blackout concerns, Hilbert decided to have a minimal number of floors rewired. To rewire a floor is to change the floor it sends power to. In the sample diagram above, all possible blackouts can be avoided by rewiring the second floor to send power to the first floor instead of the third floor.</p>
<p>Let $F(n)$ be the sum of the minimum number of floor rewirings needed over all possible power-flow arrangements in a hotel of $n$ floors. For example, $F(3) = 6$, $F(8) = 16276736$, and $F(100) \bmod 135707531 = 84326147$.</p>
<p>Find $F(12344321) \bmod 135707531$.</p> | https://projecteuler.net/problem=522 | 96772715 |
523 | Consider the following algorithm for sorting a list:
- 1. Starting from the beginning of the list, check each pair of adjacent elements in turn.
- 2. If the elements are out of order:
- a. Move the smallest element of the pair at the beginning of the list.
- b. Restart the process from step 1.
- 3. If all pairs are in order, stop.
For example, the list $\{\,4\,1\,3\,2\,\}$ is sorted as follows:
- $\underline{4\,1}\,3\,2$ ($4$ and $1$ are out of order so move $1$ to the front of the list)
- $1\,\underline{4\,3}\,2$ ($4$ and $3$ are out of order so move $3$ to the front of the list)
- $\underline{3\,1}\,4\,2$ ($3$ and $1$ are out of order so move $1$ to the front of the list)
- $1\,3\,\underline{4\,2}$ ($4$ and $2$ are out of order so move $2$ to the front of the list)
- $\underline{2\,1}\,3\,4$ ($2$ and $1$ are out of order so move $1$ to the front of the list)
- $1\,2\,3\,4$ (The list is now sorted)
Let $F(L)$ be the number of times step 2a is executed to sort list $L$. For example, $F(\{\,4\,1\,3\,2\,\}) = 5$.
Let $E(n)$ be the expected value of $F(P)$ over all permutations $P$ of the integers $\{1, 2, \dots, n\}$.
You are given $E(4) = 3.25$ and $E(10) = 115.725$.
Find $E(30)$. Give your answer rounded to two digits after the decimal point. | <p>Consider the following algorithm for sorting a list:</p>
<ul style="list-style-type:none;"><li>1. Starting from the beginning of the list, check each pair of adjacent elements in turn.</li>
<li>2. If the elements are out of order:
<ul style="list-style-type:none;"><li>a. Move the smallest element of the pair at the beginning of the list.</li>
<li>b. Restart the process from step 1.</li></ul></li>
<li>3. If all pairs are in order, stop.</li></ul>
<p>For example, the list $\{\,4\,1\,3\,2\,\}$ is sorted as follows:</p>
<ul style="list-style-type:none;"><li>$\underline{4\,1}\,3\,2$ ($4$ and $1$ are out of order so move $1$ to the front of the list)</li>
<li>$1\,\underline{4\,3}\,2$ ($4$ and $3$ are out of order so move $3$ to the front of the list)</li>
<li>$\underline{3\,1}\,4\,2$ ($3$ and $1$ are out of order so move $1$ to the front of the list)</li>
<li>$1\,3\,\underline{4\,2}$ ($4$ and $2$ are out of order so move $2$ to the front of the list)</li>
<li>$\underline{2\,1}\,3\,4$ ($2$ and $1$ are out of order so move $1$ to the front of the list)</li>
<li>$1\,2\,3\,4$ (The list is now sorted)</li></ul>
<p>Let $F(L)$ be the number of times step 2a is executed to sort list $L$. For example, $F(\{\,4\,1\,3\,2\,\}) = 5$.</p>
<p>Let $E(n)$ be the <strong>expected value</strong> of $F(P)$ over all permutations $P$ of the integers $\{1, 2, \dots, n\}$.<br>
You are given $E(4) = 3.25$ and $E(10) = 115.725$.</p>
<p>Find $E(30)$. Give your answer rounded to two digits after the decimal point.</p> | https://projecteuler.net/problem=523 | 37125450.44 |
524 | Consider the following algorithm for sorting a list:
- 1. Starting from the beginning of the list, check each pair of adjacent elements in turn.
- 2. If the elements are out of order:
- a. Move the smallest element of the pair at the beginning of the list.
- b. Restart the process from step 1.
- 3. If all pairs are in order, stop.
For example, the list $\{\,4\,1\,3\,2\,\}$ is sorted as follows:
- $\underline{4\,1}\,3\,2$ ($4$ and $1$ are out of order so move $1$ to the front of the list)
- $1\,\underline{4\,3}\,2$ ($4$ and $3$ are out of order so move $3$ to the front of the list)
- $\underline{3\,1}\,4\,2$ ($3$ and $1$ are out of order so move $1$ to the front of the list)
- $1\,3\,\underline{4\,2}$ ($4$ and $2$ are out of order so move $2$ to the front of the list)
- $\underline{2\,1}\,3\,4$ ($2$ and $1$ are out of order so move $1$ to the front of the list)
- $1\,2\,3\,4$ (The list is now sorted)
Let $F(L)$ be the number of times step 2a is executed to sort list $L$. For example, $F(\{\,4\,1\,3\,2\,\}) = 5$.
We can list all permutations $P$ of the integers $\{1, 2, \dots, n\}$ in lexicographical order, and assign to each permutation an index $I_n(P)$ from $1$ to $n!$ corresponding to its position in the list.
Let $Q(n, k) = \min(I_n(P))$ for $F(P) = k$, the index of the first permutation requiring exactly $k$ steps to sort with First Sort. If there is no permutation for which $F(P) = k$, then $Q(n, k)$ is undefined.
For $n = 4$ we have:
| P | I4(P) | F(P) | |
| --- | --- | --- | --- |
| {1, 2, 3, 4} | 1 | 0 | Q(4, 0) = 1 |
| {1, 2, 4, 3} | 2 | 4 | Q(4, 4) = 2 |
| {1, 3, 2, 4} | 3 | 2 | Q(4, 2) = 3 |
| {1, 3, 4, 2} | 4 | 2 | |
| {1, 4, 2, 3} | 5 | 6 | Q(4, 6) = 5 |
| {1, 4, 3, 2} | 6 | 4 | |
| {2, 1, 3, 4} | 7 | 1 | Q(4, 1) = 7 |
| {2, 1, 4, 3} | 8 | 5 | Q(4, 5) = 8 |
| {2, 3, 1, 4} | 9 | 1 | |
| {2, 3, 4, 1} | 10 | 1 | |
| {2, 4, 1, 3} | 11 | 5 | |
| {2, 4, 3, 1} | 12 | 3 | Q(4, 3) = 12 |
| {3, 1, 2, 4} | 13 | 3 | |
| {3, 1, 4, 2} | 14 | 3 | |
| {3, 2, 1, 4} | 15 | 2 | |
| {3, 2, 4, 1} | 16 | 2 | |
| {3, 4, 1, 2} | 17 | 3 | |
| {3, 4, 2, 1} | 18 | 2 | |
| {4, 1, 2, 3} | 19 | 7 | Q(4, 7) = 19 |
| {4, 1, 3, 2} | 20 | 5 | |
| {4, 2, 1, 3} | 21 | 6 | |
| {4, 2, 3, 1} | 22 | 4 | |
| {4, 3, 1, 2} | 23 | 4 | |
| {4, 3, 2, 1} | 24 | 3 | |
Let $R(k) = \min(Q(n, k))$ over all $n$ for which $Q(n, k)$ is defined.
Find $R(12^{12})$. | <p>Consider the following algorithm for sorting a list:</p>
<ul style="list-style-type:none;"><li>1. Starting from the beginning of the list, check each pair of adjacent elements in turn.</li>
<li>2. If the elements are out of order:
<ul style="list-style-type:none;"><li>a. Move the smallest element of the pair at the beginning of the list.</li>
<li>b. Restart the process from step 1.</li></ul></li>
<li>3. If all pairs are in order, stop.</li></ul>
<p>For example, the list $\{\,4\,1\,3\,2\,\}$ is sorted as follows:</p>
<ul style="list-style-type:none;"><li>$\underline{4\,1}\,3\,2$ ($4$ and $1$ are out of order so move $1$ to the front of the list)</li>
<li>$1\,\underline{4\,3}\,2$ ($4$ and $3$ are out of order so move $3$ to the front of the list)</li>
<li>$\underline{3\,1}\,4\,2$ ($3$ and $1$ are out of order so move $1$ to the front of the list)</li>
<li>$1\,3\,\underline{4\,2}$ ($4$ and $2$ are out of order so move $2$ to the front of the list)</li>
<li>$\underline{2\,1}\,3\,4$ ($2$ and $1$ are out of order so move $1$ to the front of the list)</li>
<li>$1\,2\,3\,4$ (The list is now sorted)</li></ul>
<p>Let $F(L)$ be the number of times step 2a is executed to sort list $L$. For example, $F(\{\,4\,1\,3\,2\,\}) = 5$.</p>
<p>We can list all permutations $P$ of the integers $\{1, 2, \dots, n\}$ in <strong>lexicographical order</strong>, and assign to each permutation an index $I_n(P)$ from $1$ to $n!$ corresponding to its position in the list.
</p><p>Let $Q(n, k) = \min(I_n(P))$ for $F(P) = k$, the index of the first permutation requiring exactly $k$ steps to sort with First Sort. If there is no permutation for which $F(P) = k$, then $Q(n, k)$ is undefined.</p>
<p>For $n = 4$ we have:</p>
<p></p><table border="1" style="text-align:left;">
<tr><th><var>P</var></th><th><var>I</var><sub>4</sub>(<var>P</var>)</th><th><var>F</var>(<var>P</var>)</th><th></th></tr>
<tr><td>{1, 2, 3, 4}</td><td>1</td><td>0</td><td>Q(4, 0) = 1</td></tr>
<tr><td>{1, 2, 4, 3}</td><td>2</td><td>4</td><td>Q(4, 4) = 2</td></tr>
<tr><td>{1, 3, 2, 4}</td><td>3</td><td>2</td><td>Q(4, 2) = 3</td></tr>
<tr><td>{1, 3, 4, 2}</td><td>4</td><td>2</td><td></td></tr>
<tr><td>{1, 4, 2, 3}</td><td>5</td><td>6</td><td>Q(4, 6) = 5</td></tr>
<tr><td>{1, 4, 3, 2}</td><td>6</td><td>4</td><td></td></tr>
<tr><td>{2, 1, 3, 4}</td><td>7</td><td>1</td><td>Q(4, 1) = 7</td></tr>
<tr><td>{2, 1, 4, 3}</td><td>8</td><td>5</td><td>Q(4, 5) = 8</td></tr>
<tr><td>{2, 3, 1, 4}</td><td>9</td><td>1</td><td></td></tr>
<tr><td>{2, 3, 4, 1}</td><td>10</td><td>1</td><td></td></tr>
<tr><td>{2, 4, 1, 3}</td><td>11</td><td>5</td><td></td></tr>
<tr><td>{2, 4, 3, 1}</td><td>12</td><td>3</td><td>Q(4, 3) = 12</td></tr>
<tr><td>{3, 1, 2, 4}</td><td>13</td><td>3</td><td></td></tr>
<tr><td>{3, 1, 4, 2}</td><td>14</td><td>3</td><td></td></tr>
<tr><td>{3, 2, 1, 4}</td><td>15</td><td>2</td><td></td></tr>
<tr><td>{3, 2, 4, 1}</td><td>16</td><td>2</td><td></td></tr>
<tr><td>{3, 4, 1, 2}</td><td>17</td><td>3</td><td></td></tr>
<tr><td>{3, 4, 2, 1}</td><td>18</td><td>2</td><td></td></tr>
<tr><td>{4, 1, 2, 3}</td><td>19</td><td>7</td><td>Q(4, 7) = 19</td></tr>
<tr><td>{4, 1, 3, 2}</td><td>20</td><td>5</td><td></td></tr>
<tr><td>{4, 2, 1, 3}</td><td>21</td><td>6</td><td></td></tr>
<tr><td>{4, 2, 3, 1}</td><td>22</td><td>4</td><td></td></tr>
<tr><td>{4, 3, 1, 2}</td><td>23</td><td>4</td><td></td></tr>
<tr><td>{4, 3, 2, 1}</td><td>24</td><td>3</td><td></td></tr>
</table>
<p>Let $R(k) = \min(Q(n, k))$ over all $n$ for which $Q(n, k)$ is defined.</p>
<p>Find $R(12^{12})$.</p> | https://projecteuler.net/problem=524 | 2432925835413407847 |
525 | An ellipse $E(a, b)$ is given at its initial position by equation:
$\frac {x^2} {a^2} + \frac {(y - b)^2} {b^2} = 1$
The ellipse rolls without slipping along the $x$ axis for one complete turn. Interestingly, the length of the curve generated by a focus is independent from the size of the minor axis:
$F(a,b) = 2 \pi \max(a,b)$
This is not true for the curve generated by the ellipse center. Let $C(a, b)$ be the length of the curve generated by the center of the ellipse as it rolls without slipping for one turn.
You are given $C(2, 4) \approx 21.38816906$.
Find $C(1, 4) + C(3, 4)$. Give your answer rounded to $8$ digits behind the decimal point in the form ab.cdefghij. | <p>An ellipse $E(a, b)$ is given at its initial position by equation:<br>
$\frac {x^2} {a^2} + \frac {(y - b)^2} {b^2} = 1$</p>
<p>The ellipse rolls without slipping along the $x$ axis for one complete turn. Interestingly, the length of the curve generated by a focus is independent from the size of the minor axis:<br>
$F(a,b) = 2 \pi \max(a,b)$</p>
<div align="center"><img src="resources/images/0525-rolling-ellipse-1.gif?1678992057" alt="0525-rolling-ellipse-1.gif"></div>
<p>This is not true for the curve generated by the ellipse center. Let $C(a, b)$ be the length of the curve generated by the center of the ellipse as it rolls without slipping for one turn.</p>
<div align="center"><img src="resources/images/0525-rolling-ellipse-2.gif?1678992057" alt="0525-rolling-ellipse-2.gif"></div>
<p>You are given $C(2, 4) \approx 21.38816906$.</p>
<p>Find $C(1, 4) + C(3, 4)$. Give your answer rounded to $8$ digits behind the decimal point in the form <i>ab.cdefghij</i>.</p> | https://projecteuler.net/problem=525 | 44.69921807 |
526 | Let $f(n)$ be the largest prime factor of $n$.
Let $g(n) = f(n) + f(n + 1) + f(n + 2) + f(n + 3) + f(n + 4) + f(n + 5) + f(n + 6) + f(n + 7) + f(n + 8)$, the sum of the largest prime factor of each of nine consecutive numbers starting with $n$.
Let $h(n)$ be the maximum value of $g(k)$ for $2 \le k \le n$.
You are given:
- $f(100) = 5$
- $f(101) = 101$
- $g(100) = 409$
- $h(100) = 417$
- $h(10^9) = 4896292593$
Find $h(10^{16})$. | <p>Let $f(n)$ be the largest prime factor of $n$.</p>
<p>Let $g(n) = f(n) + f(n + 1) + f(n + 2) + f(n + 3) + f(n + 4) + f(n + 5) + f(n + 6) + f(n + 7) + f(n + 8)$, the sum of the largest prime factor of each of nine consecutive numbers starting with $n$.</p>
<p>Let $h(n)$ be the maximum value of $g(k)$ for $2 \le k \le n$.</p>
<p>You are given:</p>
<ul><li>$f(100) = 5$</li>
<li>$f(101) = 101$</li>
<li>$g(100) = 409$</li>
<li>$h(100) = 417$</li>
<li>$h(10^9) = 4896292593$</li></ul>
<p>Find $h(10^{16})$.</p> | https://projecteuler.net/problem=526 | 49601160286750947 |
527 | A secret integer $t$ is selected at random within the range $1 \le t \le n$.
The goal is to guess the value of $t$ by making repeated guesses, via integer $g$. After a guess is made, there are three possible outcomes, in which it will be revealed that either $g \lt t$, $g = t$, or $g \gt t$. Then the process can repeat as necessary.
Normally, the number of guesses required on average can be minimized with a binary search: Given a lower bound $L$ and upper bound $H$ (initialized to $L = 1$ and $H = n$), let $g = \lfloor(L+H)/2\rfloor$ where $\lfloor \cdot \rfloor$ is the integer floor function. If $g = t$, the process ends. Otherwise, if $g \lt t$, set $L = g+1$, but if $g \gt t$ instead, set $H = g - 1$. After setting the new bounds, the search process repeats, and ultimately ends once $t$ is found. Even if $t$ can be deduced without searching, assume that a search will be required anyway to confirm the value.
Your friend Bob believes that the standard binary search is not that much better than his randomized variant: Instead of setting $g = \lfloor(L+H)/2\rfloor$, simply let $g$ be a random integer between $L$ and $H$, inclusive. The rest of the algorithm is the same as the standard binary search. This new search routine will be referred to as a random binary search.
Given that $1 \le t \le n$ for random $t$, let $B(n)$ be the expected number of guesses needed to find $t$ using the standard binary search, and let $R(n)$ be the expected number of guesses needed to find $t$ using the random binary search. For example, $B(6) = 2.33333333$ and $R(6) = 2.71666667$ when rounded to $8$ decimal places.
Find $R(10^{10}) - B(10^{10})$ rounded to $8$ decimal places. | <p>A secret integer $t$ is selected at random within the range $1 \le t \le n$. </p>
<p>The goal is to guess the value of $t$ by making repeated guesses, via integer $g$. After a guess is made, there are three possible outcomes, in which it will be revealed that either $g \lt t$, $g = t$, or $g \gt t$. Then the process can repeat as necessary.</p>
<p>Normally, the number of guesses required on average can be minimized with a binary search: Given a lower bound $L$ and upper bound $H$ (initialized to $L = 1$ and $H = n$), let $g = \lfloor(L+H)/2\rfloor$ where $\lfloor \cdot \rfloor$ is the integer floor function. If $g = t$, the process ends. Otherwise, if $g \lt t$, set $L = g+1$, but if $g \gt t$ instead, set $H = g - 1$. After setting the new bounds, the search process repeats, and ultimately ends once $t$ is found. Even if $t$ can be deduced without searching, assume that a search will be required anyway to confirm the value.</p>
<p>Your friend Bob believes that the standard binary search is not that much better than his randomized variant: Instead of setting $g = \lfloor(L+H)/2\rfloor$, simply let $g$ be a random integer between $L$ and $H$, inclusive. The rest of the algorithm is the same as the standard binary search. This new search routine will be referred to as a <dfn>random binary search</dfn>.</p>
<p>Given that $1 \le t \le n$ for random $t$, let $B(n)$ be the expected number of guesses needed to find $t$ using the standard binary search, and let $R(n)$ be the expected number of guesses needed to find $t$ using the random binary search. For example, $B(6) = 2.33333333$ and $R(6) = 2.71666667$ when rounded to $8$ decimal places.</p>
<p>Find $R(10^{10}) - B(10^{10})$ rounded to $8$ decimal places.</p> | https://projecteuler.net/problem=527 | 11.92412011 |
528 | Let $S(n, k, b)$ represent the number of valid solutions to $x_1 + x_2 + \cdots + x_k \le n$, where $0 \le x_m \le b^m$ for all $1 \le m \le k$.
For example, $S(14,3,2) = 135$, $S(200,5,3) = 12949440$, and $S(1000,10,5) \bmod 1\,000\,000\,007 = 624839075$.
Find $(\sum_{10 \le k \le 15} S(10^k, k, k)) \bmod 1\,000\,000\,007$. | <p>Let $S(n, k, b)$ represent the number of valid solutions to $x_1 + x_2 + \cdots + x_k \le n$, where $0 \le x_m \le b^m$ for all $1 \le m \le k$.</p>
<p>For example, $S(14,3,2) = 135$, $S(200,5,3) = 12949440$, and $S(1000,10,5) \bmod 1\,000\,000\,007 = 624839075$.</p>
<p>Find $(\sum_{10 \le k \le 15} S(10^k, k, k)) \bmod 1\,000\,000\,007$.</p> | https://projecteuler.net/problem=528 | 779027989 |
529 | A $10$-substring of a number is a substring of its digits that sum to $10$. For example, the $10$-substrings of the number $3523014$ are:
- 3523014
- 3523014
- 3523014
- 3523014
A number is called $10$-substring-friendly if every one of its digits belongs to a $10$-substring. For example, $3523014$ is $10$-substring-friendly, but $28546$ is not.
Let $T(n)$ be the number of $10$-substring-friendly numbers from $1$ to $10^n$ (inclusive).
For example $T(2) = 9$ and $T(5) = 3492$.
Find $T(10^{18}) \bmod 1\,000\,000\,007$. | <p>A <dfn>$10$-substring</dfn> of a number is a substring of its digits that sum to $10$. For example, the $10$-substrings of the number $3523014$ are:</p>
<ul style="list-style-type:none;"><li><b><u>352</u></b>3014</li>
<li>3<b><u>523</u></b>014</li>
<li>3<b><u>5230</u></b>14</li>
<li>35<b><u>23014</u></b></li></ul>
<p>A number is called <dfn>$10$-substring-friendly</dfn> if every one of its digits belongs to a $10$-substring. For example, $3523014$ is $10$-substring-friendly, but $28546$ is not.</p>
<p>Let $T(n)$ be the number of $10$-substring-friendly numbers from $1$ to $10^n$ (inclusive).<br>
For example $T(2) = 9$ and $T(5) = 3492$.</p>
<p>Find $T(10^{18}) \bmod 1\,000\,000\,007$.</p> | https://projecteuler.net/problem=529 | 23624465 |
530 | Every divisor $d$ of a number $n$ has a complementary divisor $n/d$.
Let $f(n)$ be the sum of the greatest common divisor of $d$ and $n/d$ over all positive divisors $d$ of $n$, that is
$f(n)=\displaystyle\sum_{d\mid n}\gcd(d,\frac n d)$.
Let $F$ be the summatory function of $f$, that is
$F(k)=\displaystyle\sum_{n=1}^k f(n)$.
You are given that $F(10)=32$ and $F(1000)=12776$.
Find $F(10^{15})$. | <p>Every divisor $d$ of a number $n$ has a <strong>complementary divisor</strong> $n/d$.</p>
<p>Let $f(n)$ be the sum of the <strong>greatest common divisor</strong> of $d$ and $n/d$ over all positive divisors $d$ of $n$, that is
$f(n)=\displaystyle\sum_{d\mid n}\gcd(d,\frac n d)$.</p>
<p>Let $F$ be the summatory function of $f$, that is
$F(k)=\displaystyle\sum_{n=1}^k f(n)$.</p>
<p>You are given that $F(10)=32$ and $F(1000)=12776$.</p>
<p>Find $F(10^{15})$.</p> | https://projecteuler.net/problem=530 | 207366437157977206 |
531 | Let $g(a, n, b, m)$ be the smallest non-negative solution $x$ to the system:
$x = a \bmod n$
$x = b \bmod m$
if such a solution exists, otherwise $0$.
E.g. $g(2,4,4,6)=10$, but $g(3,4,4,6)=0$.
Let $\phi(n)$ be Euler's totient function.
Let $f(n,m)=g(\phi(n),n,\phi(m),m)$
Find $\sum f(n,m)$ for $1000000 \le n \lt m \lt 1005000$. | <p>
Let $g(a, n, b, m)$ be the smallest non-negative solution $x$ to the system:<br>
$x = a \bmod n$<br>
$x = b \bmod m$<br>
if such a solution exists, otherwise $0$.
</p>
<p>
E.g. $g(2,4,4,6)=10$, but $g(3,4,4,6)=0$.
</p>
<p>
Let $\phi(n)$ be Euler's totient function.
</p>
<p>
Let $f(n,m)=g(\phi(n),n,\phi(m),m)$
</p>
<p>
Find $\sum f(n,m)$ for $1000000 \le n \lt m \lt 1005000$.
</p> | https://projecteuler.net/problem=531 | 4515432351156203105 |
532 | Bob is a manufacturer of nanobots and wants to impress his customers by giving them a ball coloured by his new nanobots as a present.
His nanobots can be programmed to select and locate exactly one other bot precisely and, after activation, move towards this bot along the shortest possible path and draw a coloured line onto the surface while moving. Placed on a plane, the bots will start to move towards their selected bots in a straight line. In contrast, being placed on a ball, they will start to move along a geodesic as the shortest possible path. However, in both cases, whenever their target moves they will adjust their direction instantaneously to the new shortest possible path. All bots will move at the same speed after their simultaneous activation until each bot reaches its goal.
Now Bob places $n$ bots on the ball (with radius $1$) equidistantly on a small circle with radius $0.999$ and programs each of them to move toward the next nanobot sitting counterclockwise on that small circle. After activation, the bots move in a sort of spiral until they finally meet at one point on the ball.
Using three bots, Bob finds that every bot will draw a line of length $2.84$, resulting in a total length of $8.52$ for all three bots, each time rounded to two decimal places. The coloured ball looks like this:
In order to show off a little with his presents, Bob decides to use just enough bots to make sure that the line each bot draws is longer than $1000$. What is the total length of all lines drawn with this number of bots, rounded to two decimal places? | <p>Bob is a manufacturer of nanobots and wants to impress his customers by giving them a ball coloured by his new nanobots as a present.</p>
<p>His nanobots can be programmed to select and locate exactly one other bot precisely and, after activation, move towards this bot along the shortest possible path and draw a coloured line onto the surface while moving. Placed on a plane, the bots will start to move towards their selected bots in a straight line. In contrast, being placed on a ball, they will start to move along a geodesic as the shortest possible path. However, in both cases, whenever their target moves they will adjust their direction instantaneously to the new shortest possible path. All bots will move at the same speed after their simultaneous activation until each bot reaches its goal.</p>
<p>Now Bob places $n$ bots on the ball (with radius $1$) equidistantly on a small circle with radius $0.999$ and programs each of them to move toward the next nanobot sitting counterclockwise on that small circle. After activation, the bots move in a sort of spiral until they finally meet at one point on the ball.</p>
<p>Using three bots, Bob finds that every bot will draw a line of length $2.84$, resulting in a total length of $8.52$ for all three bots, each time rounded to two decimal places. The coloured ball looks like this:</p>
<div align="center"><img src="resources/images/0532-nanobots.jpg?1678992054" alt="0532-nanobots.jpg"></div>
<p>In order to show off a little with his presents, Bob decides to use just enough bots to make sure that the line each bot draws is longer than $1000$. What is the total length of all lines drawn with this number of bots, rounded to two decimal places?</p> | https://projecteuler.net/problem=532 | 827306.56 |
533 | The Carmichael function $\lambda(n)$ is defined as the smallest positive integer $m$ such that $a^m = 1$ modulo $n$ for all integers $a$ coprime with $n$.
For example $\lambda(8) = 2$ and $\lambda(240) = 4$.
Define $L(n)$ as the smallest positive integer $m$ such that $\lambda(k) \ge n$ for all $k \ge m$.
For example, $L(6) = 241$ and $L(100) = 20\,174\,525\,281$.
Find $L(20\,000\,000)$. Give the last $9$ digits of your answer. | <p>The <strong>Carmichael function</strong> $\lambda(n)$ is defined as the smallest positive integer $m$ such that $a^m = 1$ modulo $n$ for all integers $a$ coprime with $n$.<br>
For example $\lambda(8) = 2$ and $\lambda(240) = 4$.</p>
<p>Define $L(n)$ as the smallest positive integer $m$ such that $\lambda(k) \ge n$ for all $k \ge m$.<br>
For example, $L(6) = 241$ and $L(100) = 20\,174\,525\,281$.</p>
<p>Find $L(20\,000\,000)$. Give the last $9$ digits of your answer.</p> | https://projecteuler.net/problem=533 | 789453601 |
534 | The classical eight queens puzzle is the well known problem of placing eight chess queens on an $8 \times 8$ chessboard so that no two queens threaten each other. Allowing configurations to reappear in rotated or mirrored form, a total of $92$ distinct configurations can be found for eight queens. The general case asks for the number of distinct ways of placing $n$ queens on an $n \times n$ board, e.g. you can find $2$ distinct configurations for $n=4$.
Let's define a weak queen on an $n \times n$ board to be a piece which can move any number of squares if moved horizontally, but a maximum of $n - 1 - w$ squares if moved vertically or diagonally, $0 \le w \lt n$ being the "weakness factor". For example, a weak queen on an $n \times n$ board with a weakness factor of $w=1$ located in the bottom row will not be able to threaten any square in the top row as the weak queen would need to move $n - 1$ squares vertically or diagonally to get there, but may only move $n - 2$ squares in these directions. In contrast, the weak queen is not handicapped horizontally, thus threatening every square in its own row, independently from its current position in that row.
Let $Q(n,w)$ be the number of ways $n$ weak queens with weakness factor $w$ can be placed on an $n \times n$ board so that no two queens threaten each other. It can be shown, for example, that $Q(4,0)=2$, $Q(4,2)=16$ and $Q(4,3)=256$.
Let $S(n)=\displaystyle\sum_{w=0}^{n-1} Q(n,w)$.
You are given that $S(4)=276$ and $S(5)=3347$.
Find $S(14)$. | <p>The classical <b>eight queens puzzle</b> is the well known problem of placing eight chess queens on an $8 \times 8$ chessboard so that no two queens threaten each other. Allowing configurations to reappear in rotated or mirrored form, a total of $92$ distinct configurations can be found for eight queens. The general case asks for the number of distinct ways of placing $n$ queens on an $n \times n$ board, e.g. you can find $2$ distinct configurations for $n=4$.</p>
<p>Let's define a <dfn>weak queen</dfn> on an $n \times n$ board to be a piece which can move any number of squares if moved horizontally, but a maximum of $n - 1 - w$ squares if moved vertically or diagonally, $0 \le w \lt n$ being the "weakness factor". For example, a weak queen on an $n \times n$ board with a weakness factor of $w=1$ located in the bottom row will not be able to threaten any square in the top row as the weak queen would need to move $n - 1$ squares vertically or diagonally to get there, but may only move $n - 2$ squares in these directions. In contrast, the weak queen is not handicapped horizontally, thus threatening every square in its own row, independently from its current position in that row.</p>
<p>Let $Q(n,w)$ be the number of ways $n$ weak queens with weakness factor $w$ can be placed on an $n \times n$ board so that no two queens threaten each other. It can be shown, for example, that $Q(4,0)=2$, $Q(4,2)=16$ and $Q(4,3)=256$.</p>
<p>Let $S(n)=\displaystyle\sum_{w=0}^{n-1} Q(n,w)$.</p>
<p>You are given that $S(4)=276$ and $S(5)=3347$.</p>
<p>Find $S(14)$.</p> | https://projecteuler.net/problem=534 | 11726115562784664 |
535 | Consider the infinite integer sequence S starting with:
$S = 1, 1, 2, 1, 3, 2, 4, 1, 5, 3, 6, 2, 7, 8, 4, 9, 1, 10, 11, 5, \dots$
Circle the first occurrence of each integer.
$S = \enclose{circle}1, 1, \enclose{circle}2, 1, \enclose{circle}3, 2, \enclose{circle}4, 1, \enclose{circle}5, 3, \enclose{circle}6, 2, \enclose{circle}7, \enclose{circle}8, 4, \enclose{circle}9, 1, \enclose{circle}{10}, \enclose{circle}{11}, 5, \dots$
The sequence is characterized by the following properties:
- The circled numbers are consecutive integers starting with $1$.
- Immediately preceding each non-circled numbers $a_i$, there are exactly $\lfloor \sqrt{a_i} \rfloor$ adjacent circled numbers, where $\lfloor\,\rfloor$ is the floor function.
- If we remove all circled numbers, the remaining numbers form a sequence identical to $S$, so $S$ is a fractal sequence.
Let $T(n)$ be the sum of the first $n$ elements of the sequence.
You are given $T(1) = 1$, $T(20) = 86$, $T(10^3) = 364089$ and $T(10^9) = 498676527978348241$.
Find $T(10^{18})$. Give the last $9$ digits of your answer. | <p>Consider the infinite integer sequence S starting with:<br>
$S = 1, 1, 2, 1, 3, 2, 4, 1, 5, 3, 6, 2, 7, 8, 4, 9, 1, 10, 11, 5, \dots$</p>
<p>Circle the first occurrence of each integer.<br>
$S = \enclose{circle}1, 1, \enclose{circle}2, 1, \enclose{circle}3, 2, \enclose{circle}4, 1, \enclose{circle}5, 3, \enclose{circle}6, 2, \enclose{circle}7, \enclose{circle}8, 4, \enclose{circle}9, 1, \enclose{circle}{10}, \enclose{circle}{11}, 5, \dots$</p>
<p>The sequence is characterized by the following properties:</p>
<ul><li>The circled numbers are consecutive integers starting with $1$.</li>
<li>Immediately preceding each non-circled numbers $a_i$, there are exactly $\lfloor \sqrt{a_i} \rfloor$ adjacent circled numbers, where $\lfloor\,\rfloor$ is the floor function.</li>
<li>If we remove all circled numbers, the remaining numbers form a sequence identical to $S$, so $S$ is a <strong>fractal sequence</strong>.</li></ul>
<p>Let $T(n)$ be the sum of the first $n$ elements of the sequence.<br>
You are given $T(1) = 1$, $T(20) = 86$, $T(10^3) = 364089$ and $T(10^9) = 498676527978348241$.</p>
<p>Find $T(10^{18})$. Give the last $9$ digits of your answer.</p> | https://projecteuler.net/problem=535 | 611778217 |
536 | Let $S(n)$ be the sum of all positive integers $m$ not exceeding $n$ having the following property:
$a^{m + 4} \equiv a \pmod m$ for all integers $a$.
The values of $m \le 100$ that satisfy this property are $1, 2, 3, 5$ and $21$, thus $S(100) = 1+2+3+5+21 = 32$.
You are given $S(10^6) = 22868117$.
Find $S(10^{12})$. | <p>
Let $S(n)$ be the sum of all positive integers $m$ not exceeding $n$ having the following property:<br>
$a^{m + 4} \equiv a \pmod m$ for all integers $a$.
</p>
<p>
The values of $m \le 100$ that satisfy this property are $1, 2, 3, 5$ and $21$, thus $S(100) = 1+2+3+5+21 = 32$.<br>
You are given $S(10^6) = 22868117$.
</p>
<p>
Find $S(10^{12})$.
</p> | https://projecteuler.net/problem=536 | 3557005261906288 |
537 | Let $\pi(x)$ be the prime counting function, i.e. the number of prime numbers less than or equal to $x$.
For example,$\pi(1)=0$, $\pi(2)=1$, $\pi(100)=25$.
Let $T(n, k)$ be the number of $k$-tuples $(x_1, \dots, x_k)$ which satisfy:
1. every $x_i$ is a positive integer;
2. $\displaystyle \sum_{i=1}^k \pi(x_i)=n$
For example $T(3,3)=19$.
The $19$ tuples are $(1,1,5)$, $(1,5,1)$, $(5,1,1)$, $(1,1,6)$, $(1,6,1)$, $(6,1,1)$, $(1,2,3)$, $(1,3,2)$, $(2,1,3)$, $(2,3,1)$, $(3,1,2)$, $(3,2,1)$, $(1,2,4)$, $(1,4,2)$, $(2,1,4)$, $(2,4,1)$, $(4,1,2)$, $(4,2,1)$, $(2,2,2)$.
You are given $T(10, 10) = 869\,985$ and $T(10^3,10^3) \equiv 578\,270\,566 \pmod{1\,004\,535\,809}$.
Find $T(20\,000, 20\,000) \pmod{1\,004\,535\,809}$. | <p>
Let $\pi(x)$ be the prime counting function, i.e. the number of prime numbers less than or equal to $x$.<br>
For example,$\pi(1)=0$, $\pi(2)=1$, $\pi(100)=25$.
</p>
<p>
Let $T(n, k)$ be the number of $k$-tuples $(x_1, \dots, x_k)$ which satisfy:<br>
1. every $x_i$ is a positive integer;<br>
2. $\displaystyle \sum_{i=1}^k \pi(x_i)=n$
</p>
<p>
For example $T(3,3)=19$.<br>
The $19$ tuples are $(1,1,5)$, $(1,5,1)$, $(5,1,1)$, $(1,1,6)$, $(1,6,1)$, $(6,1,1)$, $(1,2,3)$, $(1,3,2)$, $(2,1,3)$, $(2,3,1)$, $(3,1,2)$, $(3,2,1)$, $(1,2,4)$, $(1,4,2)$, $(2,1,4)$, $(2,4,1)$, $(4,1,2)$, $(4,2,1)$, $(2,2,2)$.
</p>
<p>
You are given $T(10, 10) = 869\,985$ and $T(10^3,10^3) \equiv 578\,270\,566 \pmod{1\,004\,535\,809}$.
</p><p>
Find $T(20\,000, 20\,000) \pmod{1\,004\,535\,809}$.
</p> | https://projecteuler.net/problem=537 | 779429131 |
538 | Consider a positive integer sequence $S = (s_1, s_2, \dots, s_n)$.
Let $f(S)$ be the perimeter of the maximum-area quadrilateral whose side lengths are $4$ elements $(s_i, s_j, s_k, s_l)$ of $S$ (all $i, j, k, l$ distinct). If there are many quadrilaterals with the same maximum area, then choose the one with the largest perimeter.
For example, if $S = (8, 9, 14, 9, 27)$, then we can take the elements $(9, 14, 9, 27)$ and form an isosceles trapeziumAn isosceles trapezium (US: trapezoid) is a quadrilateral where one pair of opposite sides are parallel and of different lengths, and the other pair has the same length. with parallel side lengths $14$ and $27$ and both leg lengths $9$. The area of this quadrilateral is $127.611470879\cdots$ It can be shown that this is the largest area for any quadrilateral that can be formed using side lengths from $S$. Therefore, $f(S) = 9 + 14 + 9 + 27 = 59$.
Let $u_n = 2^{B(3n)} + 3^{B(2n)} + B(n + 1)$, where $B(k)$ is the number of $1$ bits of $k$ in base $2$.
For example, $B(6) = 2$, $B(10) = 2$ and $B(15) = 4$, and $u_5 = 2^4 + 3^2 + 2 = 27$.
Also, let $U_n$ be the sequence $(u_1, u_2, \dots, u_n)$.
For example, $U_{10} = (8, 9, 14, 9, 27, 16, 36, 9, 27, 28)$.
It can be shown that $f(U_5) = 59$, $f(U_{10}) = 118$, $f(U_{150}) = 3223$.
It can also be shown that $\sum f(U_n) = 234761$ for $4 \le n \le 150$.
Find $\sum f(U_n)$ for $4 \le n \le 3\,000\,000$. | <p>Consider a positive integer sequence $S = (s_1, s_2, \dots, s_n)$.</p>
<p>Let $f(S)$ be the perimeter of the maximum-area quadrilateral whose side lengths are $4$ elements $(s_i, s_j, s_k, s_l)$ of $S$ (all $i, j, k, l$ distinct). If there are many quadrilaterals with the same maximum area, then choose the one with the largest perimeter.</p>
<p>For example, if $S = (8, 9, 14, 9, 27)$, then we can take the elements $(9, 14, 9, 27)$ and form an <strong class="tooltip">isosceles trapezium<span class="tooltiptext">An isosceles trapezium (US: trapezoid) is a quadrilateral where one pair of opposite sides are parallel and of different lengths, and the other pair has the same length.</span></strong> with parallel side lengths $14$ and $27$ and both leg lengths $9$. The area of this quadrilateral is $127.611470879\cdots$ It can be shown that this is the largest area for any quadrilateral that can be formed using side lengths from $S$. Therefore, $f(S) = 9 + 14 + 9 + 27 = 59$.</p>
<p>Let $u_n = 2^{B(3n)} + 3^{B(2n)} + B(n + 1)$, where $B(k)$ is the number of $1$ bits of $k$ in base $2$.<br>
For example, $B(6) = 2$, $B(10) = 2$ and $B(15) = 4$, and $u_5 = 2^4 + 3^2 + 2 = 27$.</p>
<p>Also, let $U_n$ be the sequence $(u_1, u_2, \dots, u_n)$.<br>
For example, $U_{10} = (8, 9, 14, 9, 27, 16, 36, 9, 27, 28)$.</p>
<p>It can be shown that $f(U_5) = 59$, $f(U_{10}) = 118$, $f(U_{150}) = 3223$.<br>
It can also be shown that $\sum f(U_n) = 234761$ for $4 \le n \le 150$.<br>
Find $\sum f(U_n)$ for $4 \le n \le 3\,000\,000$.</p> | https://projecteuler.net/problem=538 | 22472871503401097 |
539 | Start from an ordered list of all integers from $1$ to $n$. Going from left to right, remove the first number and every other number afterward until the end of the list. Repeat the procedure from right to left, removing the right most number and every other number from the numbers left. Continue removing every other numbers, alternating left to right and right to left, until a single number remains.
Starting with $n = 9$, we have:
$\underline 1\,2\,\underline 3\,4\,\underline 5\,6\,\underline 7\,8\,\underline 9$
$2\,\underline 4\,6\,\underline 8$
$\underline 2\,6$
$6$
Let $P(n)$ be the last number left starting with a list of length $n$.
Let $\displaystyle S(n) = \sum_{k=1}^n P(k)$.
You are given $P(1)=1$, $P(9) = 6$, $P(1000)=510$, $S(1000)=268271$.
Find $S(10^{18}) \bmod 987654321$. | <p>
Start from an ordered list of all integers from $1$ to $n$. Going from left to right, remove the first number and every other number afterward until the end of the list. Repeat the procedure from right to left, removing the right most number and every other number from the numbers left. Continue removing every other numbers, alternating left to right and right to left, until a single number remains.
</p>
<p>
Starting with $n = 9$, we have:<br>
$\underline 1\,2\,\underline 3\,4\,\underline 5\,6\,\underline 7\,8\,\underline 9$<br>
$2\,\underline 4\,6\,\underline 8$<br>
$\underline 2\,6$<br>
$6$
</p>
<p>
Let $P(n)$ be the last number left starting with a list of length $n$.<br>
Let $\displaystyle S(n) = \sum_{k=1}^n P(k)$.<br>
You are given $P(1)=1$, $P(9) = 6$, $P(1000)=510$, $S(1000)=268271$.
</p>
<p>
Find $S(10^{18}) \bmod 987654321$.
</p> | https://projecteuler.net/problem=539 | 426334056 |
540 | A Pythagorean triple consists of three positive integers $a, b$ and $c$ satisfying $a^2+b^2=c^2$.
The triple is called primitive if $a, b$ and $c$ are relatively prime.
Let $P(n)$ be the number of primitive Pythagorean triples with $a \lt b \lt c \le n$.
For example $P(20) = 3$, since there are three triples: $(3,4,5)$, $(5,12,13)$ and $(8,15,17)$.
You are given that $P(10^6) = 159139$.
Find $P(3141592653589793)$. | <p>
A <strong>Pythagorean triple</strong> consists of three positive integers $a, b$ and $c$ satisfying $a^2+b^2=c^2$.<br>
The triple is called primitive if $a, b$ and $c$ are relatively prime.<br>
Let $P(n)$ be the number of <strong>primitive Pythagorean triples</strong> with $a \lt b \lt c \le n$.<br>
For example $P(20) = 3$, since there are three triples: $(3,4,5)$, $(5,12,13)$ and $(8,15,17)$.
</p>
<p>
You are given that $P(10^6) = 159139$.<br>
Find $P(3141592653589793)$.
</p> | https://projecteuler.net/problem=540 | 500000000002845 |
541 | The $n$th harmonic number $H_n$ is defined as the sum of the multiplicative inverses of the first $n$ positive integers, and can be written as a reduced fraction $a_n/b_n$.
$H_n = \displaystyle \sum_{k=1}^n \frac 1 k = \frac {a_n} {b_n}$, with $\gcd(a_n, b_n)=1$.
Let $M(p)$ be the largest value of $n$ such that $b_n$ is not divisible by $p$.
For example, $M(3) = 68$ because $H_{68} = \frac {a_{68}} {b_{68}} = \frac {14094018321907827923954201611} {2933773379069966367528193600}$, $b_{68}=2933773379069966367528193600$ is not divisible by $3$, but all larger harmonic numbers have denominators divisible by $3$.
You are given $M(7) = 719102$.
Find $M(137)$. | <p>The $n$<sup>th</sup> <strong>harmonic number</strong> $H_n$ is defined as the sum of the multiplicative inverses of the first $n$ positive integers, and can be written as a <strong>reduced fraction</strong> $a_n/b_n$.<br>
$H_n = \displaystyle \sum_{k=1}^n \frac 1 k = \frac {a_n} {b_n}$, with $\gcd(a_n, b_n)=1$.</p>
<p>Let $M(p)$ be the largest value of $n$ such that $b_n$ is not divisible by $p$.</p>
<p>For example, $M(3) = 68$ because $H_{68} = \frac {a_{68}} {b_{68}} = \frac {14094018321907827923954201611} {2933773379069966367528193600}$, $b_{68}=2933773379069966367528193600$ is not divisible by $3$, but all larger harmonic numbers have denominators divisible by $3$.</p>
<p>You are given $M(7) = 719102$.</p>
<p>Find $M(137)$.</p> | https://projecteuler.net/problem=541 | 4580726482872451 |
542 | Let $S(k)$ be the sum of three or more distinct positive integers having the following properties:
- No value exceeds $k$.
- The values form a geometric progression.
- The sum is maximal.
$S(4) = 4 + 2 + 1 = 7$
$S(10) = 9 + 6 + 4 = 19$
$S(12) = 12 + 6 + 3 = 21$
$S(1000) = 1000 + 900 + 810 + 729 = 3439$
Let $T(n) = \sum_{k=4}^n (-1)^k S(k)$.
$T(1000) = 2268$
Find $T(10^{17})$. | <p>Let $S(k)$ be the sum of three or more distinct positive integers having the following properties:</p>
<ul><li>No value exceeds $k$.</li>
<li>The values form a <strong>geometric progression</strong>.</li>
<li>The sum is maximal.</li></ul>
<p>$S(4) = 4 + 2 + 1 = 7$<br>
$S(10) = 9 + 6 + 4 = 19$<br>
$S(12) = 12 + 6 + 3 = 21$<br>
$S(1000) = 1000 + 900 + 810 + 729 = 3439$</p>
<p>Let $T(n) = \sum_{k=4}^n (-1)^k S(k)$.<br>
$T(1000) = 2268$</p>
<p>Find $T(10^{17})$.</p> | https://projecteuler.net/problem=542 | 697586734240314852 |
543 | Define function $P(n, k) = 1$ if $n$ can be written as the sum of $k$ prime numbers (with repetitions allowed), and $P(n, k) = 0$ otherwise.
For example, $P(10,2) = 1$ because $10$ can be written as either $3 + 7$ or $5 + 5$, but $P(11,2) = 0$ because no two primes can sum to $11$.
Let $S(n)$ be the sum of all $P(i,k)$ over $1 \le i,k \le n$.
For example, $S(10) = 20$, $S(100) = 2402$, and $S(1000) = 248838$.
Let $F(k)$ be the $k$th Fibonacci number (with $F(0) = 0$ and $F(1) = 1$).
Find the sum of all $S(F(k))$ over $3 \le k \le 44$. | <p>Define function $P(n, k) = 1$ if $n$ can be written as the sum of $k$ prime numbers (with repetitions allowed), and $P(n, k) = 0$ otherwise.</p>
<p>For example, $P(10,2) = 1$ because $10$ can be written as either $3 + 7$ or $5 + 5$, but $P(11,2) = 0$ because no two primes can sum to $11$.</p>
<p>Let $S(n)$ be the sum of all $P(i,k)$ over $1 \le i,k \le n$.</p>
<p>For example, $S(10) = 20$, $S(100) = 2402$, and $S(1000) = 248838$.</p>
<p>Let $F(k)$ be the $k$th Fibonacci number (with $F(0) = 0$ and $F(1) = 1$).</p>
<p>Find the sum of all $S(F(k))$ over $3 \le k \le 44$.</p> | https://projecteuler.net/problem=543 | 199007746081234640 |
544 | Let $F(r, c, n)$ be the number of ways to colour a rectangular grid with $r$ rows and $c$ columns using at most $n$ colours such that no two adjacent cells share the same colour. Cells that are diagonal to each other are not considered adjacent.
For example, $F(2,2,3) = 18$, $F(2,2,20) = 130340$, and $F(3,4,6) = 102923670$.
Let $S(r, c, n) = \sum_{k=1}^{n} F(r, c, k)$.
For example, $S(4,4,15) \bmod 10^9+7 = 325951319$.
Find $S(9,10,1112131415) \bmod 10^9+7$. | <p>Let $F(r, c, n)$ be the number of ways to colour a rectangular grid with $r$ rows and $c$ columns using at most $n$ colours such that no two adjacent cells share the same colour. Cells that are diagonal to each other are not considered adjacent.</p>
<p>For example, $F(2,2,3) = 18$, $F(2,2,20) = 130340$, and $F(3,4,6) = 102923670$.</p>
<p>Let $S(r, c, n) = \sum_{k=1}^{n} F(r, c, k)$.</p>
<p>For example, $S(4,4,15) \bmod 10^9+7 = 325951319$.</p>
<p>Find $S(9,10,1112131415) \bmod 10^9+7$.</p> | https://projecteuler.net/problem=544 | 640432376 |
545 | The sum of the $k$th powers of the first $n$ positive integers can be expressed as a polynomial of degree $k+1$ with rational coefficients, the Faulhaber's Formulas:
$1^k + 2^k + ... + n^k = \sum_{i=1}^n i^k = \sum_{i=1}^{k+1} a_{i} n^i = a_{1} n + a_{2} n^2 + ... + a_{k} n^k + a_{k+1} n^{k + 1}$,
where $a_i$'s are rational coefficients that can be written as reduced fractions $p_i/q_i$ (if $a_i = 0$, we shall consider $q_i = 1$).
For example, $1^4 + 2^4 + ... + n^4 = -\frac 1 {30} n + \frac 1 3 n^3 + \frac 1 2 n^4 + \frac 1 5 n^5.$
Define $D(k)$ as the value of $q_1$ for the sum of $k$th powers (i.e. the denominator of the reduced fraction $a_1$).
Define $F(m)$ as the $m$th value of $k \ge 1$ for which $D(k) = 20010$.
You are given $D(4) = 30$ (since $a_1 = -1/30$), $D(308) = 20010$, $F(1) = 308$, $F(10) = 96404$.
Find $F(10^5)$. | <p>The sum of the $k$<sup>th</sup> powers of the first $n$ positive integers can be expressed as a polynomial of degree $k+1$ with rational coefficients, the <strong>Faulhaber's Formulas</strong>:<br>
$1^k + 2^k + ... + n^k = \sum_{i=1}^n i^k = \sum_{i=1}^{k+1} a_{i} n^i = a_{1} n + a_{2} n^2 + ... + a_{k} n^k + a_{k+1} n^{k + 1}$,<br>
where $a_i$'s are rational coefficients that can be written as reduced fractions $p_i/q_i$ (if $a_i = 0$, we shall consider $q_i = 1$).</p>
<p>For example, $1^4 + 2^4 + ... + n^4 = -\frac 1 {30} n + \frac 1 3 n^3 + \frac 1 2 n^4 + \frac 1 5 n^5.$</p>
<p>Define $D(k)$ as the value of $q_1$ for the sum of $k$<sup>th</sup> powers (i.e. the denominator of the reduced fraction $a_1$).<br>
Define $F(m)$ as the $m$<sup>th</sup> value of $k \ge 1$ for which $D(k) = 20010$.<br>
You are given $D(4) = 30$ (since $a_1 = -1/30$), $D(308) = 20010$, $F(1) = 308$, $F(10) = 96404$.</p>
<p>Find $F(10^5)$.</p> | https://projecteuler.net/problem=545 | 921107572 |
546 | Define $f_k(n) = \sum_{i=0}^n f_k(\lfloor\frac i k \rfloor)$ where $f_k(0) = 1$ and $\lfloor x \rfloor$ denotes the floor function.
For example, $f_5(10) = 18$, $f_7(100) = 1003$, and $f_2(10^3) = 264830889564$.
Find $(\sum_{k=2}^{10} f_k(10^{14})) \bmod (10^9+7)$. | <p>Define $f_k(n) = \sum_{i=0}^n f_k(\lfloor\frac i k \rfloor)$ where $f_k(0) = 1$ and $\lfloor x \rfloor$ denotes the floor function.</p>
<p>For example, $f_5(10) = 18$, $f_7(100) = 1003$, and $f_2(10^3) = 264830889564$.</p>
<p>Find $(\sum_{k=2}^{10} f_k(10^{14})) \bmod (10^9+7)$.</p> | https://projecteuler.net/problem=546 | 215656873 |
547 | Assuming that two points are chosen randomly (with uniform distribution) within a rectangle, it is possible to determine the expected value of the distance between these two points.
For example, the expected distance between two random points in a unit square is about $0.521405$, while the expected distance between two random points in a rectangle with side lengths $2$ and $3$ is about $1.317067$.
Now we define a hollow square lamina of size $n$ to be an integer sized square with side length $n \ge 3$ consisting of $n^2$ unit squares from which a rectangle consisting of $x \times y$ unit squares ($1 \le x,y \le n - 2$) within the original square has been removed.
For $n = 3$ there exists only one hollow square lamina:
For $n = 4$ you can find $9$ distinct hollow square laminae, allowing shapes to reappear in rotated or mirrored form:
Let $S(n)$ be the sum of the expected distance between two points chosen randomly within each of the possible hollow square laminae of size $n$. The two points have to lie within the area left after removing the inner rectangle, i.e. the gray-colored areas in the illustrations above.
For example, $S(3) = 1.6514$ and $S(4) = 19.6564$, rounded to four digits after the decimal point.
Find $S(40)$ rounded to four digits after the decimal point. | <p>Assuming that two points are chosen randomly (with <strong>uniform distribution</strong>) within a rectangle, it is possible to determine the <strong>expected value</strong> of the distance between these two points.</p>
<p>For example, the expected distance between two random points in a unit square is about $0.521405$, while the expected distance between two random points in a rectangle with side lengths $2$ and $3$ is about $1.317067$.</p>
<p>Now we define a <dfn>hollow square lamina</dfn> of size $n$ to be an integer sized square with side length $n \ge 3$ consisting of $n^2$ unit squares from which a rectangle consisting of $x \times y$ unit squares ($1 \le x,y \le n - 2$) within the original square has been removed.</p>
<p>For $n = 3$ there exists only one hollow square lamina:</p>
<p align="center"><img src="resources/images/0547-holes-1.png?1678992053" alt="0547-holes-1.png"></p>
<p>For $n = 4$ you can find $9$ distinct hollow square laminae, allowing shapes to reappear in rotated or mirrored form:</p>
<p align="center"><img src="resources/images/0547-holes-2.png?1678992053" alt="0547-holes-2.png"></p>
<p>Let $S(n)$ be the sum of the expected distance between two points chosen randomly within each of the possible hollow square laminae of size $n$. The two points have to lie within the area left after removing the inner rectangle, i.e. the gray-colored areas in the illustrations above.</p>
<p>For example, $S(3) = 1.6514$ and $S(4) = 19.6564$, rounded to four digits after the decimal point.</p>
<p>Find $S(40)$ rounded to four digits after the decimal point.</p> | https://projecteuler.net/problem=547 | 11730879.0023 |
548 | A gozinta chain for $n$ is a sequence $\{1,a,b,\dots,n\}$ where each element properly divides the next.
There are eight gozinta chains for $12$:
$\{1,12\}$, $\{1,2,12\}$, $\{1,2,4,12\}$, $\{1,2,6,12\}$, $\{1,3,12\}$, $\{1,3,6,12\}$, $\{1,4,12\}$ and $\{1,6,12\}$.
Let $g(n)$ be the number of gozinta chains for $n$, so $g(12)=8$.
$g(48)=48$ and $g(120)=132$.
Find the sum of the numbers $n$ not exceeding $10^{16}$ for which $g(n)=n$. | <p>
A <strong>gozinta chain</strong> for $n$ is a sequence $\{1,a,b,\dots,n\}$ where each element properly divides the next.<br>
There are eight gozinta chains for $12$:<br>
$\{1,12\}$, $\{1,2,12\}$, $\{1,2,4,12\}$, $\{1,2,6,12\}$, $\{1,3,12\}$, $\{1,3,6,12\}$, $\{1,4,12\}$ and $\{1,6,12\}$.<br>
Let $g(n)$ be the number of gozinta chains for $n$, so $g(12)=8$.<br>
$g(48)=48$ and $g(120)=132$.
</p>
<p>
Find the sum of the numbers $n$ not exceeding $10^{16}$ for which $g(n)=n$.
</p> | https://projecteuler.net/problem=548 | 12144044603581281 |
549 | The smallest number $m$ such that $10$ divides $m!$ is $m=5$.
The smallest number $m$ such that $25$ divides $m!$ is $m=10$.
Let $s(n)$ be the smallest number $m$ such that $n$ divides $m!$.
So $s(10)=5$ and $s(25)=10$.
Let $S(n)$ be $\sum s(i)$ for $2 \le i \le n$.
$S(100)=2012$.
Find $S(10^8)$. | <p>
The smallest number $m$ such that $10$ divides $m!$ is $m=5$.<br>
The smallest number $m$ such that $25$ divides $m!$ is $m=10$.<br>
</p>
<p>
Let $s(n)$ be the smallest number $m$ such that $n$ divides $m!$.<br>
So $s(10)=5$ and $s(25)=10$.<br>
Let $S(n)$ be $\sum s(i)$ for $2 \le i \le n$.<br>
$S(100)=2012$.
</p>
<p>
Find $S(10^8)$.
</p> | https://projecteuler.net/problem=549 | 476001479068717 |
550 | Two players are playing a game, alternating turns. There are $k$ piles of stones.
On each turn, a player has to choose a pile and replace it with two piles of stones under the following two conditions:
- Both new piles must have a number of stones more than one and less than the number of stones of the original pile.
- The number of stones of each of the new piles must be a divisor of the number of stones of the original pile.
The first player unable to make a valid move loses.
Let $f(n,k)$ be the number of winning positions for the first player, assuming perfect play, when the game is played with $k$ piles each having between $2$ and $n$ stones (inclusively).
$f(10,5)=40085$.
Find $f(10^7,10^{12})$.
Give your answer modulo $987654321$. | <p>
Two players are playing a game, alternating turns. There are $k$ piles of stones.
On each turn, a player has to choose a pile and replace it with two piles of stones under the following two conditions:
</p>
<ul><li> Both new piles must have a number of stones more than one and less than the number of stones of the original pile.</li>
<li> The number of stones of each of the new piles must be a divisor of the number of stones of the original pile.</li></ul>
<p>
The first player unable to make a valid move loses.
<br>
Let $f(n,k)$ be the number of winning positions for the first player, assuming perfect play, when the game is played with $k$ piles each having between $2$ and $n$ stones (inclusively).<br>$f(10,5)=40085$.
</p>
<p>
Find $f(10^7,10^{12})$.<br>Give your answer modulo $987654321$.
</p> | https://projecteuler.net/problem=550 | 328104836 |
551 | Let $a_0, a_1, \dots$ be an integer sequence defined by:
- $a_0 = 1$;
- for $n \ge 1$, $a_n$ is the sum of the digits of all preceding terms.
The sequence starts with $1, 1, 2, 4, 8, 16, 23, 28, 38, 49, \dots$
You are given $a_{10^6} = 31054319$.
Find $a_{10^{15}}$. | <p>Let $a_0, a_1, \dots$ be an integer sequence defined by:</p>
<ul>
<li>$a_0 = 1$;</li>
<li>for $n \ge 1$, $a_n$ is the sum of the digits of all preceding terms.</li>
</ul>
<p>The sequence starts with $1, 1, 2, 4, 8, 16, 23, 28, 38, 49, \dots$<br>
You are given $a_{10^6} = 31054319$.</p>
<p>Find $a_{10^{15}}$.</p> | https://projecteuler.net/problem=551 | 73597483551591773 |
552 | Let $A_n$ be the smallest positive integer satisfying $A_n \bmod p_i = i$ for all $1 \le i \le n$, where $p_i$ is the
$i$-th prime.
For example $A_2 = 5$, since this is the smallest positive solution of the system of equations
- $A_2 \bmod 2 = 1$
- $A_2 \bmod 3 = 2$
The system of equations for $A_3$ adds another constraint. That is, $A_3$ is the smallest positive solution of
- $A_3 \bmod 2 = 1$
- $A_3 \bmod 3 = 2$
- $A_3 \bmod 5 = 3$
and hence $A_3 = 23$. Similarly, one gets $A_4 = 53$ and $A_5 = 1523$.
Let $S(n)$ be the sum of all primes up to $n$ that divide at least one element in the sequence $A$.
For example, $S(50) = 69 = 5 + 23 + 41$, since $5$ divides $A_2$, $23$ divides $A_3$ and $41$ divides $A_{10} = 5765999453$. No other prime number up to $50$ divides an element in $A$.
Find $S(300000)$. | <p>
Let $A_n$ be the smallest positive integer satisfying $A_n \bmod p_i = i$ for all $1 \le i \le n$, where $p_i$ is the
$i$-th prime.
<br>For example $A_2 = 5$, since this is the smallest positive solution of the system of equations</p>
<ul style="list-style-type:none;margin-left:2cm;"><li> $A_2 \bmod 2 = 1$ </li>
<li> $A_2 \bmod 3 = 2$ </li></ul>
<p>
The system of equations for $A_3$ adds another constraint. That is, $A_3$ is the smallest positive solution of</p>
<ul style="list-style-type:none;margin-left:2cm;"><li> $A_3 \bmod 2 = 1$ </li>
<li> $A_3 \bmod 3 = 2$ </li>
<li> $A_3 \bmod 5 = 3$ </li></ul>
<p>
and hence $A_3 = 23$. Similarly, one gets $A_4 = 53$ and $A_5 = 1523$.
</p>
<p>
Let $S(n)$ be the sum of all primes up to $n$ that divide at least one element in the sequence $A$.
<br>For example, $S(50) = 69 = 5 + 23 + 41$, since $5$ divides $A_2$, $23$ divides $A_3$ and $41$ divides $A_{10} = 5765999453$. No other prime number up to $50$ divides an element in $A$.
</p>
<p>
Find $S(300000)$.</p> | https://projecteuler.net/problem=552 | 326227335 |
553 | Let $P(n)$ be the set of the first $n$ positive integers $\{1, 2, \dots, n\}$.
Let $Q(n)$ be the set of all the non-empty subsets of $P(n)$.
Let $R(n)$ be the set of all the non-empty subsets of $Q(n)$.
An element $X \in R(n)$ is a non-empty subset of $Q(n)$, so it is itself a set.
From $X$ we can construct a graph as follows:
- Each element $Y \in X$ corresponds to a vertex and labeled with $Y$;
- Two vertices $Y_1$ and $Y_2$ are connected if $Y_1 \cap Y_2 \ne \emptyset$.
For example, $X = \{\{1\},\{1,2,3\},\{3\},\{5,6\},\{6,7\}\}$ results in the following graph:
This graph has two connected components.
Let $C(n, k)$ be the number of elements of $R(n)$ that have exactly $k$ connected components in their graph.
You are given $C(2, 1) = 6$, $C(3, 1) = 111$, $C(4, 2) = 486$, $C(100, 10) \bmod 1\,000\,000\,007 = 728209718$.
Find $C(10^4, 10) \bmod 1\,000\,000\,007$. | <p>Let $P(n)$ be the set of the first $n$ positive integers $\{1, 2, \dots, n\}$.<br>
Let $Q(n)$ be the set of all the non-empty subsets of $P(n)$.<br>
Let $R(n)$ be the set of all the non-empty subsets of $Q(n)$.</p>
<p>An element $X \in R(n)$ is a non-empty subset of $Q(n)$, so it is itself a set.<br>
From $X$ we can construct a graph as follows:</p>
<ul>
<li>Each element $Y \in X$ corresponds to a vertex and labeled with $Y$;</li>
<li>Two vertices $Y_1$ and $Y_2$ are connected if $Y_1 \cap Y_2 \ne \emptyset$.</li>
</ul>
<p>For example, $X = \{\{1\},\{1,2,3\},\{3\},\{5,6\},\{6,7\}\}$ results in the following graph:</p>
<div align="center"><img src="resources/images/0553-power-sets.gif?1678992057" alt="0553-power-sets.gif"></div>
<p>This graph has two <strong>connected components</strong>.</p>
<p>Let $C(n, k)$ be the number of elements of $R(n)$ that have exactly $k$ connected components in their graph.<br>
You are given $C(2, 1) = 6$, $C(3, 1) = 111$, $C(4, 2) = 486$, $C(100, 10) \bmod 1\,000\,000\,007 = 728209718$.</p>
<p>Find $C(10^4, 10) \bmod 1\,000\,000\,007$.</p> | https://projecteuler.net/problem=553 | 57717170 |
554 | On a chess board, a centaur moves like a king or a knight. The diagram below shows the valid moves of a centaur (represented by an inverted king) on an $8 \times 8$ board.
It can be shown that at most $n^2$ non-attacking centaurs can be placed on a board of size $2n \times 2n$.
Let $C(n)$ be the number of ways to place $n^2$ centaurs on a $2n \times 2n$ board so that no centaur attacks another directly.
For example $C(1) = 4$, $C(2) = 25$, $C(10) = 1477721$.
Let $F_i$ be the $i$th Fibonacci number defined as $F_1 = F_2 = 1$ and $F_i = F_{i - 1} + F_{i - 2}$ for $i \gt 2$.
Find $\displaystyle \left( \sum_{i=2}^{90} C(F_i) \right) \bmod (10^8+7)$. | <p>On a chess board, a centaur moves like a king or a knight. The diagram below shows the valid moves of a centaur (represented by an inverted king) on an $8 \times 8$ board.</p>
<div align="center"><img src="resources/images/0554-centaurs.png?1678992053" alt="0554-centaurs.png"></div>
<p>It can be shown that at most $n^2$ non-attacking centaurs can be placed on a board of size $2n \times 2n$.<br>
Let $C(n)$ be the number of ways to place $n^2$ centaurs on a $2n \times 2n$ board so that no centaur attacks another directly.<br>
For example $C(1) = 4$, $C(2) = 25$, $C(10) = 1477721$.</p>
<p>Let $F_i$ be the $i$<sup>th</sup> Fibonacci number defined as $F_1 = F_2 = 1$ and $F_i = F_{i - 1} + F_{i - 2}$ for $i \gt 2$.</p>
<p>Find $\displaystyle \left( \sum_{i=2}^{90} C(F_i) \right) \bmod (10^8+7)$.</p> | https://projecteuler.net/problem=554 | 89539872 |
555 | The McCarthy 91 function is defined as follows:
$$
M_{91}(n) =
\begin{cases}
n - 10 & \text{if } n > 100 \\
M_{91}(M_{91}(n+11)) & \text{if } 0 \leq n \leq 100
\end{cases}
$$
We can generalize this definition by abstracting away the constants into new variables:
$$
M_{m,k,s}(n) =
\begin{cases}
n - s & \text{if } n > m \\
M_{m,k,s}(M_{m,k,s}(n+k)) & \text{if } 0 \leq n \leq m
\end{cases}
$$
This way, we have $M_{91} = M_{100,11,10}$.
Let $F_{m,k,s}$ be the set of fixed points of $M_{m,k,s}$. That is,
$$F_{m,k,s}= \left\{ n \in \mathbb{N} \, | \, M_{m,k,s}(n) = n \right\}$$
For example, the only fixed point of $M_{91}$ is $n = 91$. In other words, $F_{100,11,10}= \{91\}$.
Now, define $SF(m,k,s)$ as the sum of the elements in $F_{m,k,s}$ and let $S(p,m) = \displaystyle \sum_{1 \leq s < k \leq p}{SF(m,k,s)}$.
For example, $S(10, 10) = 225$ and $S(1000, 1000)=208724467$.
Find $S(10^6, 10^6)$. | <p>
The McCarthy 91 function is defined as follows:
$$
M_{91}(n) =
\begin{cases}
n - 10 & \text{if } n > 100 \\
M_{91}(M_{91}(n+11)) & \text{if } 0 \leq n \leq 100
\end{cases}
$$
</p>
<p>
We can generalize this definition by abstracting away the constants into new variables:
$$
M_{m,k,s}(n) =
\begin{cases}
n - s & \text{if } n > m \\
M_{m,k,s}(M_{m,k,s}(n+k)) & \text{if } 0 \leq n \leq m
\end{cases}
$$
</p>
<p>
This way, we have $M_{91} = M_{100,11,10}$.
</p>
<p>
Let $F_{m,k,s}$ be the set of fixed points of $M_{m,k,s}$. That is,
$$F_{m,k,s}= \left\{ n \in \mathbb{N} \, | \, M_{m,k,s}(n) = n \right\}$$
</p>
<p>
For example, the only fixed point of $M_{91}$ is $n = 91$. In other words, $F_{100,11,10}= \{91\}$.
</p>
<p>
Now, define $SF(m,k,s)$ as the sum of the elements in $F_{m,k,s}$ and let $S(p,m) = \displaystyle \sum_{1 \leq s < k \leq p}{SF(m,k,s)}$.
</p>
<p>
For example, $S(10, 10) = 225$ and $S(1000, 1000)=208724467$.
</p>
<p>
Find $S(10^6, 10^6)$.
</p> | https://projecteuler.net/problem=555 | 208517717451208352 |
556 | A Gaussian integer is a number $z = a + bi$ where $a$, $b$ are integers and $i^2 = -1$.
Gaussian integers are a subset of the complex numbers, and the integers are the subset of Gaussian integers for which $b = 0$.
A Gaussian integer unit is one for which $a^2 + b^2 = 1$, i.e. one of $1, i, -1, -i$.
Let's define a proper Gaussian integer as one for which $a \gt 0$ and $b \ge 0$.
A Gaussian integer $z_1 = a_1 + b_1 i$ is said to be divisible by $z_2 = a_2 + b_2 i$ if $z_3 = a_3 + b_3 i = z_1 / z_2$ is a Gaussian integer.
$\frac {z_1} {z_2} = \frac {a_1 + b_1 i} {a_2 + b_2 i} = \frac {(a_1 + b_1 i)(a_2 - b_2 i)} {(a_2 + b_2 i)(a_2 - b_2 i)} = \frac {a_1 a_2 + b_1 b_2} {a_2^2 + b_2^2} + \frac {a_2 b_1 - a_1 b_2} {a_2^2 + b_2^2}i = a_3 + b_3 i$
So, $z_1$ is divisible by $z_2$ if $\frac {a_1 a_2 + b_1 b_2} {a_2^2 + b_2^2}$ and $\frac {a_2 b_1 - a_1 b_2} {a_2^2 + b_2^2}$ are integers.
For example, $2$ is divisible by $1 + i$ because $2/(1 + i) = 1 - i$ is a Gaussian integer.
A Gaussian prime is a Gaussian integer that is divisible only by a unit, itself or itself times a unit.
For example, $1 + 2i$ is a Gaussian prime, because it is only divisible by $1$, $i$, $-1$, $-i$, $1 + 2i$, $i(1 + 2i) = i - 2$, $-(1 + 2i) = -1 - 2i$ and $-i(1 + 2i) = 2 - i$.
$2$ is not a Gaussian prime as it is divisible by $1 + i$.
A Gaussian integer can be uniquely factored as the product of a unit and proper Gaussian primes.
For example $2 = -i(1 + i)^2$ and $1 + 3i = (1 + i)(2 + i)$.
A Gaussian integer is said to be squarefree if its prime factorization does not contain repeated proper Gaussian primes.
So $2$ is not squarefree over the Gaussian integers, but $1 + 3i$ is.
Units and Gaussian primes are squarefree by definition.
Let $f(n)$ be the count of proper squarefree Gaussian integers with $a^2 + b^2 \le n$.
For example $f(10) = 7$ because $1$, $1 + i$, $1 + 2i$, $1 + 3i = (1 + i)(2 + i)$, $2 + i$, $3$ and $3 + i = -i(1 + i)(1 + 2i)$ are squarefree, while $2 = -i(1 + i)^2$ and $2 + 2i = -i(1 + i)^3$ are not.
You are given $f(10^2) = 54$, $f(10^4) = 5218$ and $f(10^8) = 52126906$.
Find $f(10^{14})$. | <p>A <b>Gaussian integer</b> is a number $z = a + bi$ where $a$, $b$ are integers and $i^2 = -1$.<br>
Gaussian integers are a subset of the complex numbers, and the integers are the subset of Gaussian integers for which $b = 0$.</p>
<p>A Gaussian integer <strong>unit</strong> is one for which $a^2 + b^2 = 1$, i.e. one of $1, i, -1, -i$.<br>
Let's define a <dfn>proper</dfn> Gaussian integer as one for which $a \gt 0$ and $b \ge 0$.</p>
<p>A Gaussian integer $z_1 = a_1 + b_1 i$ is said to be divisible by $z_2 = a_2 + b_2 i$ if $z_3 = a_3 + b_3 i = z_1 / z_2$ is a Gaussian integer.<br>
$\frac {z_1} {z_2} = \frac {a_1 + b_1 i} {a_2 + b_2 i} = \frac {(a_1 + b_1 i)(a_2 - b_2 i)} {(a_2 + b_2 i)(a_2 - b_2 i)} = \frac {a_1 a_2 + b_1 b_2} {a_2^2 + b_2^2} + \frac {a_2 b_1 - a_1 b_2} {a_2^2 + b_2^2}i = a_3 + b_3 i$<br>
So, $z_1$ is divisible by $z_2$ if $\frac {a_1 a_2 + b_1 b_2} {a_2^2 + b_2^2}$ and $\frac {a_2 b_1 - a_1 b_2} {a_2^2 + b_2^2}$ are integers.<br>
For example, $2$ is divisible by $1 + i$ because $2/(1 + i) = 1 - i$ is a Gaussian integer.</p>
<p>A <strong>Gaussian prime</strong> is a Gaussian integer that is divisible only by a unit, itself or itself times a unit.<br>
For example, $1 + 2i$ is a Gaussian prime, because it is only divisible by $1$, $i$, $-1$, $-i$, $1 + 2i$, $i(1 + 2i) = i - 2$, $-(1 + 2i) = -1 - 2i$ and $-i(1 + 2i) = 2 - i$.<br>
$2$ is not a Gaussian prime as it is divisible by $1 + i$.</p>
<p>A Gaussian integer can be uniquely factored as the product of a unit and proper Gaussian primes.<br>
For example $2 = -i(1 + i)^2$ and $1 + 3i = (1 + i)(2 + i)$.<br>
A Gaussian integer is said to be squarefree if its prime factorization does not contain repeated proper Gaussian primes.<br>
So $2$ is not squarefree over the Gaussian integers, but $1 + 3i$ is.<br>
Units and Gaussian primes are squarefree by definition.</p>
<p>Let $f(n)$ be the count of proper squarefree Gaussian integers with $a^2 + b^2 \le n$.<br>
For example $f(10) = 7$ because $1$, $1 + i$, $1 + 2i$, $1 + 3i = (1 + i)(2 + i)$, $2 + i$, $3$ and $3 + i = -i(1 + i)(1 + 2i)$ are squarefree, while $2 = -i(1 + i)^2$ and $2 + 2i = -i(1 + i)^3$ are not.<br>
You are given $f(10^2) = 54$, $f(10^4) = 5218$ and $f(10^8) = 52126906$.</p>
<p>Find $f(10^{14})$.</p> | https://projecteuler.net/problem=556 | 52126939292957 |
557 | A triangle is cut into four pieces by two straight lines, each starting at one vertex and ending on the opposite edge. This results in forming three smaller triangular pieces, and one quadrilateral. If the original triangle has an integral area, it is often possible to choose cuts such that all of the four pieces also have integral area. For example, the diagram below shows a triangle of area $55$ that has been cut in this way.
Representing the areas as $a, b, c$ and $d$, in the example above, the individual areas are $a = 22$, $b = 8$, $c = 11$ and $d = 14$. It is also possible to cut a triangle of area $55$ such that $a = 20$, $b = 2$, $c = 24$, $d = 9$.
Define a triangle cutting quadruple $(a, b, c, d)$ as a valid integral division of a triangle, where $a$ is the area of the triangle between the two cut vertices, $d$ is the area of the quadrilateral and $b$ and $c$ are the areas of the two other triangles, with the restriction that $b \le c$. The two solutions described above are $(22,8,11,14)$ and $(20,2,24,9)$. These are the only two possible quadruples that have a total area of $55$.
Define $S(n)$ as the sum of the area of the uncut triangles represented by all valid quadruples with $a+b+c+d \le n$.
For example, $S(20) = 259$.
Find $S(10000)$. | <p>
A triangle is cut into four pieces by two straight lines, each starting at one vertex and ending on the opposite edge. This results in forming three smaller triangular pieces, and one quadrilateral. If the original triangle has an integral area, it is often possible to choose cuts such that all of the four pieces also have integral area. For example, the diagram below shows a triangle of area $55$ that has been cut in this way.
</p>
<div align="center"><img src="resources/images/0557-triangle.gif?1678992057" alt="0557-triangle.gif"></div>
<p>
Representing the areas as $a, b, c$ and $d$, in the example above, the individual areas are $a = 22$, $b = 8$, $c = 11$ and $d = 14$. It is also possible to cut a triangle of area $55$ such that $a = 20$, $b = 2$, $c = 24$, $d = 9$.</p>
<p>
Define a triangle cutting quadruple $(a, b, c, d)$ as a valid integral division of a triangle, where $a$ is the area of the triangle between the two cut vertices, $d$ is the area of the quadrilateral and $b$ and $c$ are the areas of the two other triangles, with the restriction that $b \le c$. The two solutions described above are $(22,8,11,14)$ and $(20,2,24,9)$. These are the only two possible quadruples that have a total area of $55$.
</p>
<p>
Define $S(n)$ as the sum of the area of the uncut triangles represented by all valid quadruples with $a+b+c+d \le n$.<br> For example, $S(20) = 259$.
</p>
<p>
Find $S(10000)$.
</p> | https://projecteuler.net/problem=557 | 2699929328 |
558 | Let $r$ be the real root of the equation $x^3 = x^2 + 1$.
Every positive integer can be written as the sum of distinct increasing powers of $r$.
If we require the number of terms to be finite and the difference between any two exponents to be three or more, then the representation is unique.
For example, $3 = r^{-10} + r^{-5} + r^{-1} + r^2$ and $10 = r^{-10} + r^{-7} + r^6$.
Interestingly, the relation holds for the complex roots of the equation.
Let $w(n)$ be the number of terms in this unique representation of $n$. Thus $w(3) = 4$ and $w(10) = 3$.
More formally, for all positive integers $n$, we have:
$n = \displaystyle \sum_{k=-\infty}^\infty b_k r^k$
under the conditions that:
$b_k$ is $0$ or $1$ for all $k$;
$b_k + b_{k + 1} + b_{k + 2} \le 1$ for all $k$;
$w(n) = \displaystyle \sum_{k=-\infty}^\infty b_k$ is finite.
Let $S(m) = \displaystyle \sum_{j=1}^m w(j^2)$.
You are given $S(10) = 61$ and $S(1000) = 19403$.
Find $S(5\,000\,000)$. | <p>Let $r$ be the real root of the equation $x^3 = x^2 + 1$.<br>
Every positive integer can be written as the sum of distinct increasing powers of $r$.<br>
If we require the number of terms to be finite and the difference between any two exponents to be three or more, then the representation is unique.<br>
For example, $3 = r^{-10} + r^{-5} + r^{-1} + r^2$ and $10 = r^{-10} + r^{-7} + r^6$.<br>
Interestingly, the relation holds for the complex roots of the equation.</p>
<p>Let $w(n)$ be the number of terms in this unique representation of $n$. Thus $w(3) = 4$ and $w(10) = 3$.</p>
<p>More formally, for all positive integers $n$, we have:<br>
$n = \displaystyle \sum_{k=-\infty}^\infty b_k r^k$<br>
under the conditions that:<br>
$b_k$ is $0$ or $1$ for all $k$;<br>
$b_k + b_{k + 1} + b_{k + 2} \le 1$ for all $k$;<br>
$w(n) = \displaystyle \sum_{k=-\infty}^\infty b_k$ is finite.</p>
<p>Let $S(m) = \displaystyle \sum_{j=1}^m w(j^2)$.<br>
You are given $S(10) = 61$ and $S(1000) = 19403$.</p>
<p>Find $S(5\,000\,000)$.</p> | https://projecteuler.net/problem=558 | 226754889 |
559 | An ascent of a column $j$ in a matrix occurs if the value of column $j$ is smaller than the value of column $j + 1$ in all rows.
Let $P(k, r, n)$ be the number of $r \times n$ matrices with the following properties:
- The rows are permutations of $\{1, 2, 3, \dots, n\}$.
- Numbering the first column as $1$, a column ascent occurs at column $j \lt n$ if and only if $j$ is not a multiple of $k$.
For example, $P(1, 2, 3) = 19$, $P(2, 4, 6) = 65508751$ and $P(7, 5, 30) \bmod 1000000123 = 161858102$.
Let $Q(n) = \displaystyle \sum_{k=1}^n P(k, n, n)$.
For example, $Q(5) = 21879393751$ and $Q(50) \bmod 1000000123 = 819573537$.
Find $Q(50000) \bmod 1000000123$. | <p>An <dfn>ascent</dfn> of a column $j$ in a matrix occurs if the value of column $j$ is smaller than the value of column $j + 1$ in all rows.
</p><p>
Let $P(k, r, n)$ be the number of $r \times n$ matrices with the following properties:</p>
<ul><li>The rows are permutations of $\{1, 2, 3, \dots, n\}$.</li>
<li> Numbering the first column as $1$, a column ascent occurs at column $j \lt n$ <b>if and only if</b> $j$ is not a multiple of $k$.</li>
</ul><p>For example, $P(1, 2, 3) = 19$, $P(2, 4, 6) = 65508751$ and $P(7, 5, 30) \bmod 1000000123 = 161858102$.</p>
Let $Q(n) = \displaystyle \sum_{k=1}^n P(k, n, n)$.<br>
For example, $Q(5) = 21879393751$ and $Q(50) \bmod 1000000123 = 819573537$.
<p>Find $Q(50000) \bmod 1000000123$.</p> | https://projecteuler.net/problem=559 | 684724920 |
560 | Coprime Nim is just like ordinary normal play Nim, but the players may only remove a number of stones from a pile that is coprime with the current size of the pile. Two players remove stones in turn. The player who removes the last stone wins.
Let $L(n, k)$ be the number of losing starting positions for the first player, assuming perfect play, when the game is played with $k$ piles, each having between $1$ and $n - 1$ stones inclusively.
For example, $L(5, 2) = 6$ since the losing initial positions are $(1, 1)$, $(2, 2)$, $(2, 4)$, $(3, 3)$, $(4, 2)$ and $(4, 4)$.
You are also given $L(10, 5) = 9964$, $L(10, 10) = 472400303$, $L(10^3, 10^3) \bmod 1\,000\,000\,007 = 954021836$.
Find $L(10^7, 10^7)\bmod 1\,000\,000\,007$. | <p>Coprime Nim is just like ordinary normal play Nim, but the players may only remove a number of stones from a pile that is <strong>coprime</strong> with the current size of the pile. Two players remove stones in turn. The player who removes the last stone wins.</p>
<p>Let $L(n, k)$ be the number of <strong>losing</strong> starting positions for the first player, assuming perfect play, when the game is played with $k$ piles, each having between $1$ and $n - 1$ stones inclusively.</p>
<p>For example, $L(5, 2) = 6$ since the losing initial positions are $(1, 1)$, $(2, 2)$, $(2, 4)$, $(3, 3)$, $(4, 2)$ and $(4, 4)$.<br>
You are also given $L(10, 5) = 9964$, $L(10, 10) = 472400303$, $L(10^3, 10^3) \bmod 1\,000\,000\,007 = 954021836$.</p>
<p>Find $L(10^7, 10^7)\bmod 1\,000\,000\,007$.</p> | https://projecteuler.net/problem=560 | 994345168 |
561 | Let $S(n)$ be the number of pairs $(a,b)$ of distinct divisors of $n$ such that $a$ divides $b$.
For $n=6$ we get the following pairs: $(1,2), (1,3), (1,6),( 2,6)$ and $(3,6)$. So $S(6)=5$.
Let $p_m\#$ be the product of the first $m$ prime numbers, so $p_2\# = 2*3 = 6$.
Let $E(m, n)$ be the highest integer $k$ such that $2^k$ divides $S((p_m\#)^n)$.
$E(2,1) = 0$ since $2^0$ is the highest power of 2 that divides S(6)=5.
Let $Q(n)=\sum_{i=1}^{n} E(904961, i)$
$Q(8)=2714886$.
Evaluate $Q(10^{12})$. | <p>
Let $S(n)$ be the number of pairs $(a,b)$ of distinct divisors of $n$ such that $a$ divides $b$.<br>
For $n=6$ we get the following pairs: $(1,2), (1,3), (1,6),( 2,6)$ and $(3,6)$. So $S(6)=5$.<br>
Let $p_m\#$ be the product of the first $m$ prime numbers, so $p_2\# = 2*3 = 6$.<br>
Let $E(m, n)$ be the highest integer $k$ such that $2^k$ divides $S((p_m\#)^n)$.<br>
$E(2,1) = 0$ since $2^0$ is the highest power of 2 that divides S(6)=5.<br>
Let $Q(n)=\sum_{i=1}^{n} E(904961, i)$<br>
$Q(8)=2714886$.
</p>
<p>
Evaluate $Q(10^{12})$.
</p> | https://projecteuler.net/problem=561 | 452480999988235494 |
562 | Construct triangle $ABC$ such that:
- Vertices $A$, $B$ and $C$ are lattice points inside or on the circle of radius $r$ centered at the origin;
- the triangle contains no other lattice point inside or on its edges;
- the perimeter is maximum.
Let $R$ be the circumradius of triangle $ABC$ and $T(r) = R/r$.
For $r = 5$, one possible triangle has vertices $(-4,-3)$, $(4,2)$ and $(1,0)$ with perimeter $\sqrt{13}+\sqrt{34}+\sqrt{89}$ and circumradius $R = \sqrt {\frac {19669} 2 }$, so $T(5) = \sqrt {\frac {19669} {50} }$.
You are given $T(10) \approx 97.26729$ and $T(100) \approx 9157.64707$.
Find $T(10^7)$. Give your answer rounded to the nearest integer. | <p>Construct triangle $ABC$ such that:</p>
<ul><li>Vertices $A$, $B$ and $C$ are lattice points inside or on the circle of radius $r$ centered at the origin;</li>
<li>the triangle contains no other lattice point inside or on its edges;</li>
<li>the perimeter is maximum.</li></ul>
<p>Let $R$ be the circumradius of triangle $ABC$ and $T(r) = R/r$.<br>
For $r = 5$, one possible triangle has vertices $(-4,-3)$, $(4,2)$ and $(1,0)$ with perimeter $\sqrt{13}+\sqrt{34}+\sqrt{89}$ and circumradius $R = \sqrt {\frac {19669} 2 }$, so $T(5) = \sqrt {\frac {19669} {50} }$.<br>
You are given $T(10) \approx 97.26729$ and $T(100) \approx 9157.64707$.</p>
<p>Find $T(10^7)$. Give your answer rounded to the nearest integer.</p> | https://projecteuler.net/problem=562 | 51208732914368 |
563 | A company specialises in producing large rectangular metal sheets, starting from unit square metal plates. The welding is performed by a range of robots of increasing size. Unfortunately, the programming options of these robots are rather limited. Each one can only process up to $25$ identical rectangles of metal, which they can weld along either edge to produce a larger rectangle. The only programmable variables are the number of rectangles to be processed (up to and including $25$), and whether to weld the long or short edge.
For example, the first robot could be programmed to weld together $11$ raw unit square plates to make a $11 \times 1$ strip. The next could take $10$ of these $11 \times 1$ strips, and weld them either to make a longer $110 \times 1$ strip, or a $11 \times 10$ rectangle. Many, but not all, possible dimensions of metal sheets can be constructed in this way.
One regular customer has a particularly unusual order: The finished product should have an exact area, and the long side must not be more than $10\%$ larger than the short side. If these requirements can be met in more than one way, in terms of the exact dimensions of the two sides, then the customer will demand that all variants be produced. For example, if the order calls for a metal sheet of area $889200$, then there are three final dimensions that can be produced: $900 \times 988$, $912 \times 975$ and $936 \times 950$. The target area of $889200$ is the smallest area which can be manufactured in three different variants, within the limitations of the robot welders.
Let $M(n)$ be the minimal area that can be manufactured in exactly $n$ variants with the longer edge not greater than $10\%$ bigger than the shorter edge. Hence $M(3) = 889200$.
Find $\sum_{n=2}^{100} M(n)$. | <p>A company specialises in producing large rectangular metal sheets, starting from unit square metal plates. The welding is performed by a range of robots of increasing size. Unfortunately, the programming options of these robots are rather limited. Each one can only process up to $25$ identical rectangles of metal, which they can weld along either edge to produce a larger rectangle. The only programmable variables are the number of rectangles to be processed (up to and including $25$), and whether to weld the long or short edge.</p>
<p>For example, the first robot could be programmed to weld together $11$ raw unit square plates to make a $11 \times 1$ strip. The next could take $10$ of these $11 \times 1$ strips, and weld them either to make a longer $110 \times 1$ strip, or a $11 \times 10$ rectangle. Many, but not all, possible dimensions of metal sheets can be constructed in this way.</p>
<p>One regular customer has a particularly unusual order: The finished product should have an exact area, and the long side must not be more than $10\%$ larger than the short side. If these requirements can be met in more than one way, in terms of the exact dimensions of the two sides, then the customer will demand that all variants be produced. For example, if the order calls for a metal sheet of area $889200$, then there are three final dimensions that can be produced: $900 \times 988$, $912 \times 975$ and $936 \times 950$. The target area of $889200$ is the smallest area which can be manufactured in three different variants, within the limitations of the robot welders.</p>
<p>Let $M(n)$ be the minimal area that can be manufactured in <u>exactly</u> $n$ variants with the longer edge not greater than $10\%$ bigger than the shorter edge. Hence $M(3) = 889200$.</p>
<p>Find $\sum_{n=2}^{100} M(n)$.</p> | https://projecteuler.net/problem=563 | 27186308211734760 |
564 | A line segment of length $2n-3$ is randomly split into $n$ segments of integer length ($n \ge 3$). In the sequence given by this split, the segments are then used as consecutive sides of a convex $n$-polygon, formed in such a way that its area is maximal. All of the $\binom{2n-4} {n-1}$ possibilities for splitting up the initial line segment occur with the same probability.
Let $E(n)$ be the expected value of the area that is obtained by this procedure.
For example, for $n=3$ the only possible split of the line segment of length $3$ results in three line segments with length $1$, that form an equilateral triangle with an area of $\frac 1 4 \sqrt{3}$. Therefore $E(3)=0.433013$, rounded to $6$ decimal places.
For $n=4$ you can find $4$ different possible splits, each of which is composed of three line segments with length $1$ and one line segment with length $2$. All of these splits lead to the same maximal quadrilateral with an area of $\frac 3 4 \sqrt{3}$, thus $E(4)=1.299038$, rounded to $6$ decimal places.
Let $S(k)=\displaystyle \sum_{n=3}^k E(n)$.
For example, $S(3)=0.433013$, $S(4)=1.732051$, $S(5)=4.604767$ and $S(10)=66.955511$, rounded to $6$ decimal places each.
Find $S(50)$, rounded to $6$ decimal places. | <p>A line segment of length $2n-3$ is randomly split into $n$ segments of integer length ($n \ge 3$). In the sequence given by this split, the segments are then used as consecutive sides of a convex $n$-polygon, formed in such a way that its area is maximal. All of the $\binom{2n-4} {n-1}$ possibilities for splitting up the initial line segment occur with the same probability. </p>
<p>Let $E(n)$ be the expected value of the area that is obtained by this procedure.<br>
For example, for $n=3$ the only possible split of the line segment of length $3$ results in three line segments with length $1$, that form an equilateral triangle with an area of $\frac 1 4 \sqrt{3}$. Therefore $E(3)=0.433013$, rounded to $6$ decimal places.<br>
For $n=4$ you can find $4$ different possible splits, each of which is composed of three line segments with length $1$ and one line segment with length $2$. All of these splits lead to the same maximal quadrilateral with an area of $\frac 3 4 \sqrt{3}$, thus $E(4)=1.299038$, rounded to $6$ decimal places.</p>
<p>Let $S(k)=\displaystyle \sum_{n=3}^k E(n)$.<br>
For example, $S(3)=0.433013$, $S(4)=1.732051$, $S(5)=4.604767$ and $S(10)=66.955511$, rounded to $6$ decimal places each.</p>
<p>Find $S(50)$, rounded to $6$ decimal places.</p> | https://projecteuler.net/problem=564 | 12363.698850 |
565 | Let $\sigma(n)$ be the sum of the divisors of $n$.
E.g. the divisors of $4$ are $1$, $2$ and $4$, so $\sigma(4)=7$.
The numbers $n$ not exceeding $20$ such that $7$ divides $\sigma(n)$ are: $4$, $12$, $13$ and $20$, the sum of these numbers being $49$.
Let $S(n, d)$ be the sum of the numbers $i$ not exceeding $n$ such that $d$ divides $\sigma(i)$.
So $S(20 , 7)=49$.
You are given: $S(10^6,2017)=150850429$ and $S(10^9, 2017)=249652238344557$.
Find $S(10^{11}, 2017)$. | <p>Let $\sigma(n)$ be the sum of the divisors of $n$.<br>
E.g. the divisors of $4$ are $1$, $2$ and $4$, so $\sigma(4)=7$.
</p>
<p>
The numbers $n$ not exceeding $20$ such that $7$ divides $\sigma(n)$ are: $4$, $12$, $13$ and $20$, the sum of these numbers being $49$.
</p>
<p>
Let $S(n, d)$ be the sum of the numbers $i$ not exceeding $n$ such that $d$ divides $\sigma(i)$.<br>
So $S(20 , 7)=49$.
</p>
<p>
You are given: $S(10^6,2017)=150850429$ and $S(10^9, 2017)=249652238344557$.
</p>
<p>
Find $S(10^{11}, 2017)$.
</p> | https://projecteuler.net/problem=565 | 2992480851924313898 |
566 | Adam plays the following game with his birthday cake.
He cuts a piece forming a circular sector of $60$ degrees and flips the piece upside down, with the icing on the bottom.
He then rotates the cake by $60$ degrees counterclockwise, cuts an adjacent $60$ degree piece and flips it upside down.
He keeps repeating this, until after a total of twelve steps, all the icing is back on top.
Amazingly, this works for any piece size, even if the cutting angle is an irrational number: all the icing will be back on top after a finite number of steps.
Now, Adam tries something different: he alternates cutting pieces of size $x=\frac{360}{9}$ degrees, $y=\frac{360}{10}$ degrees and $z=\frac{360 }{\sqrt{11}}$ degrees. The first piece he cuts has size $x$ and he flips it. The second has size $y$ and he flips it. The third has size $z$ and he flips it. He repeats this with pieces of size $x$, $y$ and $z$ in that order until all the icing is back on top, and discovers he needs $60$ flips altogether.
Let $F(a, b, c)$ be the minimum number of piece flips needed to get all the icing back on top for pieces of size $x=\frac{360}{a}$ degrees, $y=\frac{360}{b}$ degrees and $z=\frac{360}{\sqrt{c}}$ degrees.
Let $G(n) = \sum_{9 \le a \lt b \lt c \le n} F(a,b,c)$, for integers $a$, $b$ and $c$.
You are given that $F(9, 10, 11) = 60$, $F(10, 14, 16) = 506$, $F(15, 16, 17) = 785232$.
You are also given $G(11) = 60$, $G(14) = 58020$ and $G(17) = 1269260$.
Find $G(53)$. | <p>Adam plays the following game with his birthday cake.</p>
<p>He cuts a piece forming a circular sector of $60$ degrees and flips the piece upside down, with the icing on the bottom.<br>
He then rotates the cake by $60$ degrees counterclockwise, cuts an adjacent $60$ degree piece and flips it upside down.<br>
He keeps repeating this, until after a total of twelve steps, all the icing is back on top.</p>
<p>Amazingly, this works for any piece size, even if the cutting angle is an irrational number: all the icing will be back on top after a finite number of steps.</p>
<p>Now, Adam tries something different: he alternates cutting pieces of size $x=\frac{360}{9}$ degrees, $y=\frac{360}{10}$ degrees and $z=\frac{360 }{\sqrt{11}}$ degrees. The first piece he cuts has size $x$ and he flips it. The second has size $y$ and he flips it. The third has size $z$ and he flips it. He repeats this with pieces of size $x$, $y$ and $z$ in that order until all the icing is back on top, and discovers he needs $60$ flips altogether.</p>
<div align="center"><img src="resources/images/0566-cakeicingpuzzle.gif?1678992057" alt="0566-cakeicingpuzzle.gif"></div>
<p>Let $F(a, b, c)$ be the minimum number of piece flips needed to get all the icing back on top for pieces of size $x=\frac{360}{a}$ degrees, $y=\frac{360}{b}$ degrees and $z=\frac{360}{\sqrt{c}}$ degrees.<br>
Let $G(n) = \sum_{9 \le a \lt b \lt c \le n} F(a,b,c)$, for integers $a$, $b$ and $c$.</p>
<p>You are given that $F(9, 10, 11) = 60$, $F(10, 14, 16) = 506$, $F(15, 16, 17) = 785232$.<br>
You are also given $G(11) = 60$, $G(14) = 58020$ and $G(17) = 1269260$.</p>
<p>Find $G(53)$.</p> | https://projecteuler.net/problem=566 | 329569369413585 |
567 | Tom has built a random generator that is connected to a row of $n$ light bulbs. Whenever the random generator is activated each of the $n$ lights is turned on with the probability of $\frac 1 2$, independently of its former state or the state of the other light bulbs.
While discussing with his friend Jerry how to use his generator, they invent two different games, they call the reciprocal games:
Both games consist of $n$ turns. Each turn is started by choosing a number $k$ randomly between (and including) $1$ and $n$, with equal probability of $\frac 1 n$ for each number, while the possible win for that turn is the reciprocal of $k$, that is $\frac 1 k$.
In game A, Tom activates his random generator once in each turn. If the number of lights turned on is the same as the previously chosen number $k$, Jerry wins and gets $\frac 1 k$, otherwise he will receive nothing for that turn. Jerry's expected win after playing the total game A consisting of $n$ turns is called $J_A(n)$. For example $J_A(6)=0.39505208$, rounded to $8$ decimal places.
For each turn in game B, after $k$ has been randomly selected, Tom keeps reactivating his random generator until exactly $k$ lights are turned on. After that Jerry takes over and reactivates the random generator until he, too, has generated a pattern with exactly $k$ lights turned on. If this pattern is identical to Tom's last pattern, Jerry wins and gets $\frac 1 k$, otherwise he will receive nothing. Jerry's expected win after the total game B consisting of $n$ turns is called $J_B(n)$. For example $J_B(6)=0.43333333$, rounded to $8$ decimal places.
Let $\displaystyle S(m)=\sum_{n=1}^m (J_A(n)+J_B(n))$. For example $S(6)=7.58932292$, rounded to $8$ decimal places.
Find $S(123456789)$, rounded to $8$ decimal places. | <p>Tom has built a random generator that is connected to a row of $n$ light bulbs. Whenever the random generator is activated each of the $n$ lights is turned on with the probability of $\frac 1 2$, independently of its former state or the state of the other light bulbs.</p>
<p>While discussing with his friend Jerry how to use his generator, they invent two different games, they call the <dfn>reciprocal games</dfn>:<br>
Both games consist of $n$ turns. Each turn is started by choosing a number $k$ randomly between (and including) $1$ and $n$, with equal probability of $\frac 1 n$ for each number, while the possible win for that turn is the reciprocal of $k$, that is $\frac 1 k$.</p>
<p>In game A, Tom activates his random generator once in each turn. If the number of lights turned on is the same as the previously chosen number $k$, Jerry wins and gets $\frac 1 k$, otherwise he will receive nothing for that turn. Jerry's expected win after playing the total game A consisting of $n$ turns is called $J_A(n)$. For example $J_A(6)=0.39505208$, rounded to $8$ decimal places.</p>
<p>For each turn in game B, after $k$ has been randomly selected, Tom keeps reactivating his random generator until exactly $k$ lights are turned on. After that Jerry takes over and reactivates the random generator until he, too, has generated a pattern with exactly $k$ lights turned on. If this pattern is identical to Tom's last pattern, Jerry wins and gets $\frac 1 k$, otherwise he will receive nothing. Jerry's expected win after the total game B consisting of $n$ turns is called $J_B(n)$. For example $J_B(6)=0.43333333$, rounded to $8$ decimal places.</p>
<p>Let $\displaystyle S(m)=\sum_{n=1}^m (J_A(n)+J_B(n))$. For example $S(6)=7.58932292$, rounded to $8$ decimal places.</p>
<p>Find $S(123456789)$, rounded to $8$ decimal places.</p> | https://projecteuler.net/problem=567 | 75.44817535 |
568 | Tom has built a random generator that is connected to a row of $n$ light bulbs. Whenever the random generator is activated each of the $n$ lights is turned on with the probability of $\frac 1 2$, independently of its former state or the state of the other light bulbs.
While discussing with his friend Jerry how to use his generator, they invent two different games, they call the reciprocal games:
Both games consist of $n$ turns. Each turn is started by choosing a number $k$ randomly between (and including) $1$ and $n$, with equal probability of $\frac 1 n$ for each number, while the possible win for that turn is the reciprocal of $k$, that is $\frac 1 k$.
In game A, Tom activates his random generator once in each turn. If the number of lights turned on is the same as the previously chosen number $k$, Jerry wins and gets $\frac 1 k$, otherwise he will receive nothing for that turn. Jerry's expected win after playing the total game A consisting of $n$ turns is called $J_A(n)$. For example $J_A(6)=0.39505208$, rounded to $8$ decimal places.
For each turn in game B, after $k$ has been randomly selected, Tom keeps reactivating his random generator until exactly $k$ lights are turned on. After that Jerry takes over and reactivates the random generator until he, too, has generated a pattern with exactly $k$ lights turned on. If this pattern is identical to Tom's last pattern, Jerry wins and gets $\frac 1 k$, otherwise he will receive nothing. Jerry's expected win after the total game B consisting of $n$ turns is called $J_B(n)$. For example $J_B(6)=0.43333333$, rounded to $8$ decimal places.
Let $D(n)=J_B(n)−J_A(n)$. For example, $D(6) = 0.03828125$.
Find the $7$ most significant digits of $D(123456789)$ after removing all leading zeros.
(If, for example, we had asked for the $7$ most significant digits of $D(6)$, the answer would have been 3828125.) | <p>Tom has built a random generator that is connected to a row of $n$ light bulbs. Whenever the random generator is activated each of the $n$ lights is turned on with the probability of $\frac 1 2$, independently of its former state or the state of the other light bulbs.</p>
<p>While discussing with his friend Jerry how to use his generator, they invent two different games, they call the <dfn>reciprocal games</dfn>:<br>
Both games consist of $n$ turns. Each turn is started by choosing a number $k$ randomly between (and including) $1$ and $n$, with equal probability of $\frac 1 n$ for each number, while the possible win for that turn is the reciprocal of $k$, that is $\frac 1 k$.</p>
<p>In game A, Tom activates his random generator once in each turn. If the number of lights turned on is the same as the previously chosen number $k$, Jerry wins and gets $\frac 1 k$, otherwise he will receive nothing for that turn. Jerry's expected win after playing the total game A consisting of $n$ turns is called $J_A(n)$. For example $J_A(6)=0.39505208$, rounded to $8$ decimal places.</p>
<p>For each turn in game B, after $k$ has been randomly selected, Tom keeps reactivating his random generator until exactly $k$ lights are turned on. After that Jerry takes over and reactivates the random generator until he, too, has generated a pattern with exactly $k$ lights turned on. If this pattern is identical to Tom's last pattern, Jerry wins and gets $\frac 1 k$, otherwise he will receive nothing. Jerry's expected win after the total game B consisting of $n$ turns is called $J_B(n)$. For example $J_B(6)=0.43333333$, rounded to $8$ decimal places.</p>
<p>Let $D(n)=J_B(n)−J_A(n)$. For example, $D(6) = 0.03828125$.</p>
<p>Find the $7$ most significant digits of $D(123456789)$ after removing all leading zeros.<br>
(If, for example, we had asked for the $7$ most significant digits of $D(6)$, the answer would have been 3828125.)</p> | https://projecteuler.net/problem=568 | 4228020 |
569 | A mountain range consists of a line of mountains with slopes of exactly $45^\circ$, and heights governed by the prime numbers, $p_n$. The up-slope of the $k$th mountain is of height $p_{2k - 1}$, and the downslope is $p_{2k}$. The first few foot-hills of this range are illustrated below.
Tenzing sets out to climb each one in turn, starting from the lowest. At the top of each peak, he looks back and counts how many of the previous peaks he can see. In the example above, the eye-line from the third mountain is drawn in red, showing that he can only see the peak of the second mountain from this viewpoint. Similarly, from the $9$th mountain, he can see three peaks, those of the $5$th, $7$th and $8$th mountain.
Let $P(k)$ be the number of peaks that are visible looking back from the $k$th mountain. Hence $P(3)=1$ and $P(9)=3$.
Also $\displaystyle \sum_{k=1}^{100} P(k) = 227$.
Find $\displaystyle \sum_{k=1}^{2500000} P(k)$. | <p>A <dfn>mountain range</dfn> consists of a line of mountains with slopes of exactly $45^\circ$, and heights governed by the prime numbers, $p_n$. The up-slope of the $k$<sup>th</sup> mountain is of height $p_{2k - 1}$, and the downslope is $p_{2k}$. The first few foot-hills of this range are illustrated below.</p>
<div class="center">
<img src="resources/images/0569-prime-mountain-range.gif?1678992057" alt="0569-prime-mountain-range.gif">
</div>
<p>Tenzing sets out to climb each one in turn, starting from the lowest. At the top of each peak, he looks back and counts how many of the previous peaks he can see. In the example above, the eye-line from the third mountain is drawn in red, showing that he can only see the peak of the second mountain from this viewpoint. Similarly, from the $9$<sup>th</sup> mountain, he can see three peaks, those of the $5$<sup>th</sup>, $7$<sup>th</sup> and $8$<sup>th</sup> mountain.</p>
<p>Let $P(k)$ be the number of peaks that are visible looking back from the $k$<sup>th</sup> mountain. Hence $P(3)=1$ and $P(9)=3$.<br>
Also $\displaystyle \sum_{k=1}^{100} P(k) = 227$.</p>
<p>Find $\displaystyle \sum_{k=1}^{2500000} P(k)$.</p> | https://projecteuler.net/problem=569 | 21025060 |
570 | A snowflake of order $n$ is formed by overlaying an equilateral triangle (rotated by $180$ degrees) onto each equilateral triangle of the same size in a snowflake of order $n-1$. A snowflake of order $1$ is a single equilateral triangle.
Some areas of the snowflake are overlaid repeatedly. In the above picture, blue represents the areas that are one layer thick, red two layers thick, yellow three layers thick, and so on.
For an order $n$ snowflake, let $A(n)$ be the number of triangles that are one layer thick, and let $B(n)$ be the number of triangles that are three layers thick. Define $G(n) = \gcd(A(n), B(n))$.
E.g. $A(3) = 30$, $B(3) = 6$, $G(3)=6$.
$A(11) = 3027630$, $B(11) = 19862070$, $G(11) = 30$.
Further, $G(500) = 186$ and $\sum_{n=3}^{500}G(n)=5124$.
Find $\displaystyle \sum_{n=3}^{10^7}G(n)$. | <p>A snowflake of order $n$ is formed by overlaying an equilateral triangle (rotated by $180$ degrees) onto each equilateral triangle of the same size in a snowflake of order $n-1$. A snowflake of order $1$ is a single equilateral triangle.</p>
<div> <img src="resources/images/0570-snowflakes.png?1678992053" alt="0570-snowflakes.png"> </div>
<p>Some areas of the snowflake are overlaid repeatedly. In the above picture, blue represents the areas that are one layer thick, red two layers thick, yellow three layers thick, and so on.</p>
<p>For an order $n$ snowflake, let $A(n)$ be the number of triangles that are one layer thick, and let $B(n)$ be the number of triangles that are three layers thick. Define $G(n) = \gcd(A(n), B(n))$.</p>
<p>E.g. $A(3) = 30$, $B(3) = 6$, $G(3)=6$.<br>
$A(11) = 3027630$, $B(11) = 19862070$, $G(11) = 30$.</p>
<p>Further, $G(500) = 186$ and $\sum_{n=3}^{500}G(n)=5124$.</p>
<p>Find $\displaystyle \sum_{n=3}^{10^7}G(n)$.</p> | https://projecteuler.net/problem=570 | 271197444 |
571 | A positive number is pandigital in base $b$ if it contains all digits from $0$ to $b - 1$ at least once when written in base $b$.
An $n$-super-pandigital number is a number that is simultaneously pandigital in all bases from $2$ to $n$ inclusively.
For example $978 = 1111010010_2 = 1100020_3 = 33102_4 = 12403_5$ is the smallest $5$-super-pandigital number.
Similarly, $1093265784$ is the smallest $10$-super-pandigital number.
The sum of the $10$ smallest $10$-super-pandigital numbers is $20319792309$.
What is the sum of the $10$ smallest $12$-super-pandigital numbers? | <p>A positive number is <strong>pandigital</strong> in base $b$ if it contains all digits from $0$ to $b - 1$ at least once when written in base $b$.</p>
<p>An <dfn>$n$-super-pandigital</dfn> number is a number that is simultaneously pandigital in all bases from $2$ to $n$ inclusively.<br>
For example $978 = 1111010010_2 = 1100020_3 = 33102_4 = 12403_5$ is the smallest $5$-super-pandigital number.<br>
Similarly, $1093265784$ is the smallest $10$-super-pandigital number.<br>
The sum of the $10$ smallest $10$-super-pandigital numbers is $20319792309$.</p>
<p>What is the sum of the $10$ smallest $12$-super-pandigital numbers?</p> | https://projecteuler.net/problem=571 | 30510390701978 |
572 | A matrix $M$ is called idempotent if $M^2 = M$.
Let $M$ be a three by three matrix :
$M=\begin{pmatrix}
a & b & c\\
d & e & f\\
g &h &i\\
\end{pmatrix}$.
Let $C(n)$ be the number of idempotent three by three matrices $M$ with integer elements such that
$ -n \le a,b,c,d,e,f,g,h,i \le n$.
$C(1)=164$ and $C(2)=848$.
Find $C(200)$. | <p>
A matrix $M$ is called idempotent if $M^2 = M$.<br>
Let $M$ be a three by three matrix :
$M=\begin{pmatrix}
a & b & c\\
d & e & f\\
g &h &i\\
\end{pmatrix}$.<br>
Let $C(n)$ be the number of idempotent three by three matrices $M$ with integer elements such that<br>
$ -n \le a,b,c,d,e,f,g,h,i \le n$.</p>
<p>
$C(1)=164$ and $C(2)=848$.
</p>
<p>
Find $C(200)$.
</p> | https://projecteuler.net/problem=572 | 19737656 |
573 | $n$ runners in very different training states want to compete in a race. Each one of them is given a different starting number $k$ $(1\leq k \leq n)$ according to the runner's (constant) individual racing speed being $v_k=\frac{k}{n}$.
In order to give the slower runners a chance to win the race, $n$ different starting positions are chosen randomly (with uniform distribution) and independently from each other within the racing track of length $1$. After this, the starting position nearest to the goal is assigned to runner $1$, the next nearest starting position to runner $2$ and so on, until finally the starting position furthest away from the goal is assigned to runner $n$. The winner of the race is the runner who reaches the goal first.
Interestingly, the expected running time for the winner is $\frac{1}{2}$, independently of the number of runners. Moreover, while it can be shown that all runners will have the same expected running time of $\frac{n}{n+1}$, the race is still unfair, since the winning chances may differ significantly for different starting numbers:
Let $P_{n,k}$ be the probability for runner $k$ to win a race with $n$ runners and $E_n = \sum_{k=1}^n k P_{n,k}$ be the expected starting number of the winner in that race. It can be shown that, for example,
$P_{3,1}=\frac{4}{9}$, $P_{3,2}=\frac{2}{9}$, $P_{3,3}=\frac{1}{3}$ and $E_3=\frac{17}{9}$ for a race with $3$ runners.
You are given that $E_4=2.21875$, $E_5=2.5104$ and $E_{10}=3.66021568$.
Find $E_{1000000}$ rounded to $4$ digits after the decimal point. | <p>$n$ runners in very different training states want to compete in a race. Each one of them is given a different starting number $k$ $(1\leq k \leq n)$ according to the runner's (constant) individual racing speed being $v_k=\frac{k}{n}$.<br>
In order to give the slower runners a chance to win the race, $n$ different starting positions are chosen randomly (with uniform distribution) and independently from each other within the racing track of length $1$. After this, the starting position nearest to the goal is assigned to runner $1$, the next nearest starting position to runner $2$ and so on, until finally the starting position furthest away from the goal is assigned to runner $n$. The winner of the race is the runner who reaches the goal first.</p>
<p>Interestingly, the expected running time for the winner is $\frac{1}{2}$, independently of the number of runners. Moreover, while it can be shown that all runners will have the same expected running time of $\frac{n}{n+1}$, the race is still unfair, since the winning chances may differ significantly for different starting numbers:</p>
<p>Let $P_{n,k}$ be the probability for runner $k$ to win a race with $n$ runners and $E_n = \sum_{k=1}^n k P_{n,k}$ be the expected starting number of the winner in that race. It can be shown that, for example,
$P_{3,1}=\frac{4}{9}$, $P_{3,2}=\frac{2}{9}$, $P_{3,3}=\frac{1}{3}$ and $E_3=\frac{17}{9}$ for a race with $3$ runners. <br>
You are given that $E_4=2.21875$, $E_5=2.5104$ and $E_{10}=3.66021568$.</p>
<p>Find $E_{1000000}$ rounded to $4$ digits after the decimal point.</p> | https://projecteuler.net/problem=573 | 1252.9809 |
574 | Let $q$ be a prime and $A \ge B >0$ be two integers with the following properties:
- $A$ and $B$ have no prime factor in common, that is $\gcd(A,B)=1$.
- The product $AB$ is divisible by every prime less than q.
It can be shown that, given these conditions, any sum $A+B<q^2$ and any difference $1<A-B<q^2$ has to be a prime number. Thus you can verify that a number $p$ is prime by showing that either $p=A+B<q^2$ or $p=A-B<q^2$ for some $A,B,q$ fulfilling the conditions listed above.
Let $V(p)$ be the smallest possible value of $A$ in any sum $p=A+B$ and any difference $p=A-B$, that verifies $p$ being prime. Examples:
$V(2)=1$, since $2=1+1< 2^2$.
$V(37)=22$, since $37=22+15=2 \cdot 11+3 \cdot 5< 7^2$ is the associated sum with the smallest possible $A$.
$V(151)=165$ since $151=165-14=3 \cdot 5 \cdot 11 - 2 \cdot 7<13^2$ is the associated difference with the smallest possible $A$.
Let $S(n)$ be the sum of $V(p)$ for all primes $p<n$. For example, $S(10)=10$ and $S(200)=7177$.
Find $S(3800)$. | <p>Let $q$ be a prime and $A \ge B >0$ be two integers with the following properties:
</p><ul><li> $A$ and $B$ have no prime factor in common, that is $\gcd(A,B)=1$.</li>
<li> The product $AB$ is divisible by every prime less than q.</li>
</ul><p>It can be shown that, given these conditions, any sum $A+B<q^2$ and any difference $1<A-B<q^2$ has to be a prime number. Thus you can verify that a number $p$ is prime by showing that either $p=A+B<q^2$ or $p=A-B<q^2$ for some $A,B,q$ fulfilling the conditions listed above.</p>
<p>Let $V(p)$ be the smallest possible value of $A$ in any sum $p=A+B$ and any difference $p=A-B$, that verifies $p$ being prime. Examples:<br>
$V(2)=1$, since $2=1+1< 2^2$. <br>
$V(37)=22$, since $37=22+15=2 \cdot 11+3 \cdot 5< 7^2$ is the associated sum with the smallest possible $A$.<br>
$V(151)=165$ since $151=165-14=3 \cdot 5 \cdot 11 - 2 \cdot 7<13^2$ is the associated difference with the smallest possible $A$. </p>
<p>
Let $S(n)$ be the sum of $V(p)$ for all primes $p<n$. For example, $S(10)=10$ and $S(200)=7177$.</p>
<p>
Find $S(3800)$.
</p> | https://projecteuler.net/problem=574 | 5780447552057000454 |
575 | It was quite an ordinary day when a mysterious alien vessel appeared as if from nowhere. After waiting several hours and receiving no response it is decided to send a team to investigate, of which you are included. Upon entering the vessel you are met by a friendly holographic figure, Katharina, who explains the purpose of the vessel, Eulertopia.
She claims that Eulertopia is almost older than time itself. Its mission was to take advantage of a combination of incredible computational power and vast periods of time to discover the answer to life, the universe, and everything. Hence the resident cleaning robot, Leonhard, along with his housekeeping responsibilities, was built with a powerful computational matrix to ponder the meaning of life as he wanders through a massive 1000 by 1000 square grid of rooms. She goes on to explain that the rooms are numbered sequentially from left to right, row by row. So, for example, if Leonhard was wandering around a 5 by 5 grid then the rooms would be numbered in the following way.
Many millenia ago Leonhard reported to Katharina to have found the answer and he is willing to share it with any life form who proves to be worthy of such knowledge.
Katharina further explains that the designers of Leonhard were given instructions to program him with equal probability of remaining in the same room or travelling to an adjacent room. However, it was not clear to them if this meant (i) an equal probability being split equally between remaining in the room and the number of available routes, or, (ii) an equal probability (50%) of remaining in the same room and then the other 50% was to be split equally between the number of available routes.
(i) Probability of remaining related to number of exits
(ii) Fixed 50% probability of remaining
The records indicate that they decided to flip a coin. Heads would mean that the probability of remaining was dynamically related to the number of exits whereas tails would mean that they program Leonhard with a fixed 50% probability of remaining in a particular room. Unfortunately there is no record of the outcome of the coin, so without further information we would need to assume that there is equal probability of either of the choices being implemented.
Katharina suggests it should not be too challenging to determine that the probability of finding him in a square numbered room in a 5 by 5 grid after unfathomable periods of time would be approximately 0.177976190476 [12 d.p.].
In order to prove yourself worthy of visiting the great oracle you must calculate the probability of finding him in a square numbered room in the 1000 by 1000 lair in which he has been wandering.
(Give your answer rounded to 12 decimal places) | <p>It was quite an ordinary day when a mysterious alien vessel appeared as if from nowhere. After waiting several hours and receiving no response it is decided to send a team to investigate, of which you are included. Upon entering the vessel you are met by a friendly holographic figure, Katharina, who explains the purpose of the vessel, Eulertopia.</p>
<p>She claims that Eulertopia is almost older than time itself. Its mission was to take advantage of a combination of incredible computational power and vast periods of time to discover the answer to life, the universe, and everything. Hence the resident cleaning robot, Leonhard, along with his housekeeping responsibilities, was built with a powerful computational matrix to ponder the meaning of life as he wanders through a massive 1000 by 1000 square grid of rooms. She goes on to explain that the rooms are numbered sequentially from left to right, row by row. So, for example, if Leonhard was wandering around a 5 by 5 grid then the rooms would be numbered in the following way.</p>
<div class="center">
<img src="resources/images/0575_wandering_robot_1_5x5.png?1678992053" alt="0575_wandering_robot_1_5x5.png">
</div>
<p>Many millenia ago Leonhard reported to Katharina to have found the answer and he is willing to share it with any life form who proves to be worthy of such knowledge.</p>
<p>Katharina further explains that the designers of Leonhard were given instructions to program him with equal probability of remaining in the same room or travelling to an adjacent room. However, it was not clear to them if this meant (i) an equal probability being split equally between remaining in the room and the number of available routes, or, (ii) an equal probability (50%) of remaining in the same room and then the other 50% was to be split equally between the number of available routes.</p>
<div class="center">
<img src="resources/images/0575_wandering_robot_2_fixed.png?1678992053" alt="0575_wandering_robot_2_fixed.png"><br>
<div style="font-style:italic;">(i) Probability of remaining related to number of exits</div>
<br>
<img src="resources/images/0575_wandering_robot_3_dynamic.png?1678992053" alt="0575_wandering_robot_3_dynamic.png"><br>
<div style="font-style:italic;">(ii) Fixed 50% probability of remaining</div>
</div>
<p>The records indicate that they decided to flip a coin. Heads would mean that the probability of remaining was dynamically related to the number of exits whereas tails would mean that they program Leonhard with a fixed 50% probability of remaining in a particular room. Unfortunately there is no record of the outcome of the coin, so without further information we would need to assume that there is equal probability of either of the choices being implemented.</p>
<p>Katharina suggests it should not be too challenging to determine that the probability of finding him in a square numbered room in a 5 by 5 grid after unfathomable periods of time would be approximately 0.177976190476 [12 d.p.].</p>
<p>In order to prove yourself worthy of visiting the great oracle you must calculate the probability of finding him in a square numbered room in the 1000 by 1000 lair in which he has been wandering.<br>
(Give your answer rounded to 12 decimal places)</p> | https://projecteuler.net/problem=575 | 0.000989640561 |
576 | A bouncing point moves counterclockwise along a circle with circumference $1$ with jumps of constant length $l \lt 1$, until it hits a gap of length $g \lt 1$, that is placed in a distance $d$ counterclockwise from the starting point. The gap does not include the starting point, that is $g+d \lt 1$.
Let $S(l,g,d)$ be the sum of the length of all jumps, until the point falls into the gap. It can be shown that $S(l,g,d)$ is finite for any irrational jump size $l$, regardless of the values of $g$ and $d$.
Examples:
$S(\sqrt{\frac 1 2}, 0.06, 0.7)=0.7071 \cdots$, $S(\sqrt{\frac 1 2}, 0.06, 0.3543)=1.4142 \cdots$ and
$S(\sqrt{\frac 1 2}, 0.06, 0.2427)=16.2634 \cdots$.
Let $M(n, g)$ be the maximum of $ \sum S(\sqrt{\frac 1 p}, g, d)$ for all primes $p \le n$ and any valid value of $d$.
Examples:
$M(3, 0.06) =29.5425 \cdots$, since $S(\sqrt{\frac 1 2}, 0.06, 0.2427)+S(\sqrt{\frac 1 3}, 0.06, 0.2427)=29.5425 \cdots$ is the maximal reachable sum for $g=0.06$.
$M(10, 0.01)=266.9010 \cdots$
Find $M(100, 0.00002)$, rounded to $4$ decimal places. | <p>
A bouncing point moves counterclockwise along a circle with circumference $1$ with jumps of constant length $l \lt 1$, until it hits a gap of length $g \lt 1$, that is placed in a distance $d$ counterclockwise from the starting point. The gap does not include the starting point, that is $g+d \lt 1$.</p>
<p>Let $S(l,g,d)$ be the sum of the length of all jumps, until the point falls into the gap. It can be shown that $S(l,g,d)$ is finite for any irrational jump size $l$, regardless of the values of $g$ and $d$.<br>
Examples: <br>
$S(\sqrt{\frac 1 2}, 0.06, 0.7)=0.7071 \cdots$, $S(\sqrt{\frac 1 2}, 0.06, 0.3543)=1.4142 \cdots$ and <br> $S(\sqrt{\frac 1 2}, 0.06, 0.2427)=16.2634 \cdots$.</p>
<p>
Let $M(n, g)$ be the maximum of $ \sum S(\sqrt{\frac 1 p}, g, d)$ for all primes $p \le n$ and any valid value of $d$.<br>
Examples:<br>
$M(3, 0.06) =29.5425 \cdots$, since $S(\sqrt{\frac 1 2}, 0.06, 0.2427)+S(\sqrt{\frac 1 3}, 0.06, 0.2427)=29.5425 \cdots$ is the maximal reachable sum for $g=0.06$. <br>
$M(10, 0.01)=266.9010 \cdots$ </p>
<p>Find $M(100, 0.00002)$, rounded to $4$ decimal places.</p> | https://projecteuler.net/problem=576 | 344457.5871 |
577 | An equilateral triangle with integer side length $n \ge 3$ is divided into $n^2$ equilateral triangles with side length 1 as shown in the diagram below.
The vertices of these triangles constitute a triangular lattice with $\frac{(n+1)(n+2)} 2$ lattice points.
Let $H(n)$ be the number of all regular hexagons that can be found by connecting 6 of these points.
For example, $H(3)=1$, $H(6)=12$ and $H(20)=966$.
Find $\displaystyle \sum_{n=3}^{12345} H(n)$. | <p>An equilateral triangle with integer side length $n \ge 3$ is divided into $n^2$ equilateral triangles with side length 1 as shown in the diagram below.<br>
The vertices of these triangles constitute a triangular lattice with $\frac{(n+1)(n+2)} 2$ lattice points.</p>
<p>Let $H(n)$ be the number of all regular hexagons that can be found by connecting 6 of these points.</p>
<div class="center">
<img src="resources/images/0577_counting_hexagons.png?1678992053" alt="0577_counting_hexagons.png">
</div>
<p>
For example, $H(3)=1$, $H(6)=12$ and $H(20)=966$.</p>
<p>Find $\displaystyle \sum_{n=3}^{12345} H(n)$.</p> | https://projecteuler.net/problem=577 | 265695031399260211 |
578 | Any positive integer can be written as a product of prime powers: $p_1^{a_1} \times p_2^{a_2} \times \cdots \times p_k^{a_k}$,
where $p_i$ are distinct prime integers, $a_i \gt 0$ and $p_i \lt p_j$ if $i \lt j$.
A decreasing prime power positive integer is one for which $a_i \ge a_j$ if $i \lt j$.
For example, $1$, $2$, $15=3 \times 5$, $360=2^3 \times 3^2 \times 5$ and $1000=2^3 \times 5^3$ are decreasing prime power integers.
Let $C(n)$ be the count of decreasing prime power positive integers not exceeding $n$.
$C(100) = 94$ since all positive integers not exceeding $100$ have decreasing prime powers except $18$, $50$, $54$, $75$, $90$ and $98$.
You are given $C(10^6) = 922052$.
Find $C(10^{13})$. | <p>Any positive integer can be written as a product of prime powers: $p_1^{a_1} \times p_2^{a_2} \times \cdots \times p_k^{a_k}$,<br>
where $p_i$ are distinct prime integers, $a_i \gt 0$ and $p_i \lt p_j$ if $i \lt j$.</p>
<p>A <dfn>decreasing prime power</dfn> positive integer is one for which $a_i \ge a_j$ if $i \lt j$.<br>
For example, $1$, $2$, $15=3 \times 5$, $360=2^3 \times 3^2 \times 5$ and $1000=2^3 \times 5^3$ are decreasing prime power integers.</p>
<p>Let $C(n)$ be the count of decreasing prime power positive integers not exceeding $n$.<br>
$C(100) = 94$ since all positive integers not exceeding $100$ have decreasing prime powers except $18$, $50$, $54$, $75$, $90$ and $98$.<br>
You are given $C(10^6) = 922052$.</p>
<p>Find $C(10^{13})$.</p> | https://projecteuler.net/problem=578 | 9219696799346 |
579 | A lattice cube is a cube in which all vertices have integer coordinates. Let $C(n)$ be the number of different lattice cubes in which the coordinates of all vertices range between (and including) $0$ and $n$. Two cubes are hereby considered different if any of their vertices have different coordinates.
For example, $C(1)=1$, $C(2)=9$, $C(4)=100$, $C(5)=229$, $C(10)=4469$ and $C(50)=8154671$.
Different cubes may contain different numbers of lattice points.
For example, the cube with the vertices
$(0, 0, 0)$, $(3, 0, 0)$, $(0, 3, 0)$, $(0, 0, 3)$, $(0, 3, 3)$, $(3, 0, 3)$, $(3, 3, 0)$, $(3, 3, 3)$ contains $64$ lattice points ($56$ lattice points on the surface including the $8$ vertices and $8$ points within the cube).
In contrast, the cube with the vertices
$(0, 2, 2)$, $(1, 4, 4)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 2, 5)$, $(3, 5, 2)$, $(4, 1, 1)$, $(5, 3, 3)$ contains only $40$ lattice points ($20$ points on the surface and $20$ points within the cube), although both cubes have the same side length $3$.
Let $S(n)$ be the sum of the lattice points contained in the different lattice cubes in which the coordinates of all vertices range between (and including) $0$ and $n$.
For example, $S(1)=8$, $S(2)=91$, $S(4)=1878$, $S(5)=5832$, $S(10)=387003$ and $S(50)=29948928129$.
Find $S(5000) \bmod 10^9$. | <p>A <strong>lattice cube</strong> is a cube in which all vertices have integer coordinates. Let $C(n)$ be the number of different lattice cubes in which the coordinates of all vertices range between (and including) $0$ and $n$. Two cubes are hereby considered different if any of their vertices have different coordinates.<br>
For example, $C(1)=1$, $C(2)=9$, $C(4)=100$, $C(5)=229$, $C(10)=4469$ and $C(50)=8154671$.
</p>
<p>Different cubes may contain different numbers of lattice points.</p>
<p>
For example, the cube with the vertices<br>
$(0, 0, 0)$, $(3, 0, 0)$, $(0, 3, 0)$, $(0, 0, 3)$, $(0, 3, 3)$, $(3, 0, 3)$, $(3, 3, 0)$, $(3, 3, 3)$ contains $64$ lattice points ($56$ lattice points on the surface including the $8$ vertices and $8$ points within the cube). </p>
<p>In contrast, the cube with the vertices<br>
$(0, 2, 2)$, $(1, 4, 4)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 2, 5)$, $(3, 5, 2)$, $(4, 1, 1)$, $(5, 3, 3)$ contains only $40$ lattice points ($20$ points on the surface and $20$ points within the cube), although both cubes have the same side length $3$.
</p>
<p>
Let $S(n)$ be the sum of the lattice points contained in the different lattice cubes in which the coordinates of all vertices range between (and including) $0$ and $n$.</p>
<p>For example, $S(1)=8$, $S(2)=91$, $S(4)=1878$, $S(5)=5832$, $S(10)=387003$ and $S(50)=29948928129$.</p>
<p>Find $S(5000) \bmod 10^9$.</p> | https://projecteuler.net/problem=579 | 3805524 |
580 | A Hilbert number is any positive integer of the form $4k+1$ for integer $k\geq 0$. We shall define a squarefree Hilbert number as a Hilbert number which is not divisible by the square of any Hilbert number other than one. For example, $117$ is a squarefree Hilbert number, equaling $9\times13$. However $6237$ is a Hilbert number that is not squarefree in this sense, as it is divisible by $9^2$. The number $3969$ is also not squarefree, as it is divisible by both $9^2$ and $21^2$.
There are $2327192$ squarefree Hilbert numbers below $10^7$.
How many squarefree Hilbert numbers are there below $10^{16}$? | <p>
A <strong>Hilbert number</strong> is any positive integer of the form $4k+1$ for integer $k\geq 0$. We shall define a <i>squarefree Hilbert number</i> as a Hilbert number which is not divisible by the square of any Hilbert number other than one. For example, $117$ is a squarefree Hilbert number, equaling $9\times13$. However $6237$ is a Hilbert number that is not squarefree in this sense, as it is divisible by $9^2$. The number $3969$ is also not squarefree, as it is divisible by both $9^2$ and $21^2$.
</p>
<p>
There are $2327192$ squarefree Hilbert numbers below $10^7$. <br>
How many squarefree Hilbert numbers are there below $10^{16}$?
</p> | https://projecteuler.net/problem=580 | 2327213148095366 |
581 | A number is $p$-smooth if it has no prime factors larger than $p$.
Let $T$ be the sequence of triangular numbers, i.e. $T(n)=n(n+1)/2$.
Find the sum of all indices $n$ such that $T(n)$ is $47$-smooth. | <p>
A number is $p$-smooth if it has no prime factors larger than $p$.<br>
Let $T$ be the sequence of triangular numbers, i.e. $T(n)=n(n+1)/2$.<br>
Find the sum of all indices $n$ such that $T(n)$ is $47$-smooth.
</p> | https://projecteuler.net/problem=581 | 2227616372734 |
582 | Let $a, b$ and $c$ be the sides of an integer sided triangle with one angle of $120$ degrees, $a \le b \le c$ and $b-a \le 100$.
Let $T(n)$ be the number of such triangles with $c \le n$.
$T(1000)=235$ and $T(10^8)=1245$.
Find $T(10^{100})$. | <p>
Let $a, b$ and $c$ be the sides of an integer sided triangle with one angle of $120$ degrees, $a \le b \le c$ and $b-a \le 100$.<br>
Let $T(n)$ be the number of such triangles with $c \le n$.<br>
$T(1000)=235$ and $T(10^8)=1245$.<br>
Find $T(10^{100})$.
</p> | https://projecteuler.net/problem=582 | 19903 |
583 | A standard envelope shape is a convex figure consisting of an isosceles triangle (the flap) placed on top of a rectangle. An example of an envelope with integral sides is shown below. Note that to form a sensible envelope, the perpendicular height of the flap ($BCD$) must be smaller than the height of the rectangle ($ABDE$).
In the envelope illustrated, not only are all the sides integral, but also all the diagonals ($AC$, $AD$, $BD$, $BE$ and $CE$) are integral too. Let us call an envelope with these properties a Heron envelope.
Let $S(p)$ be the sum of the perimeters of all the Heron envelopes with a perimeter less than or equal to $p$.
You are given that $S(10^4) = 884680$. Find $S(10^7)$. | <p>
A standard envelope shape is a convex figure consisting of an isosceles triangle (the flap) placed on top of a rectangle. An example of an envelope with integral sides is shown below. Note that to form a sensible envelope, the perpendicular height of the flap ($BCD$) must be smaller than the height of the rectangle ($ABDE$).
</p>
<div class="center">
<img src="resources/images/0583_heron_envelope.gif?1678992057" alt="0583_heron_envelope.gif">
</div>
<p>
In the envelope illustrated, not only are all the sides integral, but also all the diagonals ($AC$, $AD$, $BD$, $BE$ and $CE$) are integral too. Let us call an envelope with these properties a <dfn>Heron envelope</dfn>.
</p>
<p>
Let $S(p)$ be the sum of the perimeters of all the Heron envelopes with a perimeter less than or equal to $p$.
</p>
<p>
You are given that $S(10^4) = 884680$. Find $S(10^7)$.
</p> | https://projecteuler.net/problem=583 | 1174137929000 |
584 | A long long time ago in a galaxy far far away, the Wimwians, inhabitants of planet WimWi, discovered an unmanned drone that had landed on their planet. On examining the drone, they uncovered a device that sought the answer for the so called "Birthday Problem". The description of the problem was as follows:
If people on your planet were to enter a very large room one by one, what will be the expected number of people in the room when you first find 3 people with Birthdays within 1 day from each other.
The description further instructed them to enter the answer into the device and send the drone into space again. Startled by this turn of events, the Wimwians consulted their best mathematicians. Each year on Wimwi has 10 days and the mathematicians assumed equally likely birthdays and ignored leap years (leap years in Wimwi have 11 days), and found 5.78688636 to be the required answer. As such, the Wimwians entered this answer and sent the drone back into space.
After traveling light years away, the drone then landed on planet Joka. The same events ensued except this time, the numbers in the device had changed due to some unknown technical issues. The description read:
If people on your planet were to enter a very large room one by one, what will be the expected number of people in the room when you first find 3 people with Birthdays within 7 days from each other.
With a 100-day year on the planet, the Jokars (inhabitants of Joka) found the answer to be 8.48967364 (rounded to 8 decimal places because the device allowed only 8 places after the decimal point) assuming equally likely birthdays. They too entered the answer into the device and launched the drone into space again.
This time the drone landed on planet Earth. As before the numbers in the problem description had changed. It read:
If people on your planet were to enter a very large room one by one, what will be the expected number of people in the room when you first find 4 people with Birthdays within 7 days from each other.
What would be the answer (rounded to eight places after the decimal point) the people of Earth have to enter into the device for a year with 365 days? Ignore leap years. Also assume that all birthdays are equally likely and independent of each other. | <p>A long long time ago in a galaxy far far away, the Wimwians, inhabitants of planet WimWi, discovered an unmanned drone that had landed on their planet. On examining the drone, they uncovered a device that sought the answer for the so called "<b>Birthday Problem</b>". The description of the problem was as follows:</p>
<p><i>If people on your planet were to enter a very large room one by one, what will be the expected number of people in the room when you first find <b>3 people with Birthdays within 1 day from each other</b>.</i></p>
<p>The description further instructed them to enter the answer into the device and send the drone into space again. Startled by this turn of events, the Wimwians consulted their best mathematicians. Each year on Wimwi has 10 days and the mathematicians assumed equally likely birthdays and ignored leap years (leap years in Wimwi have 11 days), and found 5.78688636 to be the required answer. As such, the Wimwians entered this answer and sent the drone back into space.</p>
<p>After traveling light years away, the drone then landed on planet Joka. The same events ensued except this time, the numbers in the device had changed due to some unknown technical issues. The description read:</p>
<p><i>If people on your planet were to enter a very large room one by one, what will be the expected number of people in the room when you first find <b>3 people with Birthdays within 7 days from each other</b>.</i></p>
<p>With a 100-day year on the planet, the Jokars (inhabitants of Joka) found the answer to be 8.48967364 (rounded to 8 decimal places because the device allowed only 8 places after the decimal point) assuming equally likely birthdays. They too entered the answer into the device and launched the drone into space again.</p>
<p>This time the drone landed on planet Earth. As before the numbers in the problem description had changed. It read:</p>
<p><i>If people on your planet were to enter a very large room one by one, what will be the expected number of people in the room when you first find <b>4 people with Birthdays within 7 days from each other</b>.</i></p>
<p>What would be the answer (rounded to eight places after the decimal point) the people of Earth have to enter into the device for a year with 365 days? Ignore leap years. Also assume that all birthdays are equally likely and independent of each other.</p> | https://projecteuler.net/problem=584 | 32.83822408 |
585 | Consider the term $\small \sqrt{x+\sqrt{y}+\sqrt{z}}$ that is representing a nested square root. $x$, $y$ and $z$ are positive integers and $y$ and $z$ are not allowed to be perfect squares, so the number below the outer square root is irrational. Still it can be shown that for some combinations of $x$, $y$ and $z$ the given term can be simplified into a sum and/or difference of simple square roots of integers, actually denesting the square roots in the initial expression.
Here are some examples of this denesting:
$\small \sqrt{3+\sqrt{2}+\sqrt{2}}=\sqrt{2}+\sqrt{1}=\sqrt{2}+1$
$\small \sqrt{8+\sqrt{15}+\sqrt{15}}=\sqrt{5}+\sqrt{3}$
$\small \sqrt{20+\sqrt{96}+\sqrt{12}}=\sqrt{9}+\sqrt{6}+\sqrt{3}-\sqrt{2}=3+\sqrt{6}+\sqrt{3}-\sqrt{2}$
$\small \sqrt{28+\sqrt{160}+\sqrt{108}}=\sqrt{15}+\sqrt{6}+\sqrt{5}-\sqrt{2}$
As you can see the integers used in the denested expression may also be perfect squares resulting in further simplification.
Let F($n$) be the number of different terms $\small \sqrt{x+\sqrt{y}+\sqrt{z}}$, that can be denested into the sum and/or difference of a finite number of square roots, given the additional condition that $0<x \le n$. That is,
$\small \displaystyle \sqrt{x+\sqrt{y}+\sqrt{z}}=\sum_{i=1}^k s_i\sqrt{a_i}$
with $k$, $x$, $y$, $z$ and all $a_i$ being positive integers, all $s_i =\pm 1$ and $x\le n$.
Furthermore $y$ and $z$ are not allowed to be perfect squares.
Nested roots with the same value are not considered different, for example $\small \sqrt{7+\sqrt{3}+\sqrt{27}}$, $\small \sqrt{7+\sqrt{12}+\sqrt{12}}$ and $\small \sqrt{7+\sqrt{27}+\sqrt{3}}$, that can all three be denested into $\small 2+\sqrt{3}$, would only be counted once.
You are given that $F(10)=17$, $F(15)=46$, $F(20)=86$, $F(30)=213$ and $F(100)=2918$ and $F(5000)=11134074$.
Find $F(5000000)$. | <p>Consider the term $\small \sqrt{x+\sqrt{y}+\sqrt{z}}$ that is representing a <strong>nested square root</strong>. $x$, $y$ and $z$ are positive integers and $y$ and $z$ are not allowed to be perfect squares, so the number below the outer square root is irrational. Still it can be shown that for some combinations of $x$, $y$ and $z$ the given term can be simplified into a sum and/or difference of simple square roots of integers, actually <strong>denesting</strong> the square roots in the initial expression. </p>
<p>Here are some examples of this denesting:<br>
$\small \sqrt{3+\sqrt{2}+\sqrt{2}}=\sqrt{2}+\sqrt{1}=\sqrt{2}+1$<br>
$\small \sqrt{8+\sqrt{15}+\sqrt{15}}=\sqrt{5}+\sqrt{3}$<br>
$\small \sqrt{20+\sqrt{96}+\sqrt{12}}=\sqrt{9}+\sqrt{6}+\sqrt{3}-\sqrt{2}=3+\sqrt{6}+\sqrt{3}-\sqrt{2}$<br>
$\small \sqrt{28+\sqrt{160}+\sqrt{108}}=\sqrt{15}+\sqrt{6}+\sqrt{5}-\sqrt{2}$</p>
<p>As you can see the integers used in the denested expression may also be perfect squares resulting in further simplification.</p>
<p>Let F($n$) be the number of different terms $\small \sqrt{x+\sqrt{y}+\sqrt{z}}$, that can be denested into the sum and/or difference of a finite number of square roots, given the additional condition that $0<x \le n$. That is,<br>
$\small \displaystyle \sqrt{x+\sqrt{y}+\sqrt{z}}=\sum_{i=1}^k s_i\sqrt{a_i}$<br>
with $k$, $x$, $y$, $z$ and all $a_i$ being positive integers, all $s_i =\pm 1$ and $x\le n$.<br> Furthermore $y$ and $z$ are not allowed to be perfect squares.</p>
<p>Nested roots with the same value are not considered different, for example $\small \sqrt{7+\sqrt{3}+\sqrt{27}}$, $\small \sqrt{7+\sqrt{12}+\sqrt{12}}$ and $\small \sqrt{7+\sqrt{27}+\sqrt{3}}$, that can all three be denested into $\small 2+\sqrt{3}$, would only be counted once.</p>
<p>You are given that $F(10)=17$, $F(15)=46$, $F(20)=86$, $F(30)=213$ and $F(100)=2918$ and $F(5000)=11134074$.<br>
Find $F(5000000)$.</p> | https://projecteuler.net/problem=585 | 17714439395932 |
586 | The number $209$ can be expressed as $a^2 + 3ab + b^2$ in two distinct ways:
$ \qquad 209 = 8^2 + 3\cdot 8\cdot 5 + 5^2$
$ \qquad 209 = 13^2 + 3\cdot13\cdot 1 + 1^2$
Let $f(n,r)$ be the number of integers $k$ not exceeding $n$ that can be expressed as $k=a^2 + 3ab + b^2$, with $a \gt b \gt 0$ integers, in exactly $r$ different ways.
You are given that $f(10^5, 4) = 237$ and $f(10^8, 6) = 59517$.
Find $f(10^{15}, 40)$. | <p>
The number $209$ can be expressed as $a^2 + 3ab + b^2$ in two distinct ways:
</p>
<p>
$ \qquad 209 = 8^2 + 3\cdot 8\cdot 5 + 5^2$ <br>
$ \qquad 209 = 13^2 + 3\cdot13\cdot 1 + 1^2$
</p>
<p>
Let $f(n,r)$ be the number of integers $k$ not exceeding $n$ that can be expressed as $k=a^2 + 3ab + b^2$, with $a \gt b \gt 0$ integers, in exactly $r$ different ways.
</p>
<p>
You are given that $f(10^5, 4) = 237$ and $f(10^8, 6) = 59517$.
</p>
<p>
Find $f(10^{15}, 40)$.
</p> | https://projecteuler.net/problem=586 | 82490213 |
587 | A square is drawn around a circle as shown in the diagram below on the left.
We shall call the blue shaded region the L-section.
A line is drawn from the bottom left of the square to the top right as shown in the diagram on the right.
We shall call the orange shaded region a concave triangle.
It should be clear that the concave triangle occupies exactly half of the L-section.
Two circles are placed next to each other horizontally, a rectangle is drawn around both circles, and a line is drawn from the bottom left to the top right as shown in the diagram below.
This time the concave triangle occupies approximately 36.46% of the L-section.
If $n$ circles are placed next to each other horizontally, a rectangle is drawn around the n circles, and a line is drawn from the bottom left to the top right, then it can be shown that the least value of n for which the concave triangle occupies less than 10% of the L-section is $n = 15$.
What is the least value of $n$ for which the concave triangle occupies less than 0.1% of the L-section? | <p>
A square is drawn around a circle as shown in the diagram below on the left.<br>
We shall call the blue shaded region the L-section.<br>
A line is drawn from the bottom left of the square to the top right as shown in the diagram on the right.<br>
We shall call the orange shaded region a <dfn>concave triangle</dfn>.
</p>
<div class="center">
<img src="resources/images/0587_concave_triangle_1.png?1678992053" class="dark_img" alt="0587_concave_triangle_1.png">
</div>
<p>
It should be clear that the concave triangle occupies exactly half of the L-section.
</p>
<p>
Two circles are placed next to each other horizontally, a rectangle is drawn around both circles, and a line is drawn from the bottom left to the top right as shown in the diagram below.
</p>
<div class="center">
<img src="resources/images/0587_concave_triangle_2.png?1678992053" class="dark_img" alt="0587_concave_triangle_2.png">
</div>
<p>
This time the concave triangle occupies approximately 36.46% of the L-section.
</p>
<p>
If $n$ circles are placed next to each other horizontally, a rectangle is drawn around the <var>n</var> circles, and a line is drawn from the bottom left to the top right, then it can be shown that the least value of <var>n</var> for which the concave triangle occupies less than 10% of the L-section is $n = 15$.
</p>
<p>
What is the least value of $n$ for which the concave triangle occupies less than 0.1% of the L-section?
</p> | https://projecteuler.net/problem=587 | 2240 |
588 | The coefficients in the expansion of $(x+1)^k$ are called binomial coefficients.
Analoguously the coefficients in the expansion of $(x^4+x^3+x^2+x+1)^k$ are called quintinomial coefficients.
(quintus= Latin for fifth).
Consider the expansion of $(x^4+x^3+x^2+x+1)^3$:
$x^{12}+3x^{11}+6x^{10}+10x^9+15x^8+18x^7+19x^6+18x^5+15x^4+10x^3+6x^2+3x+1$
As we can see $7$ out of the $13$ quintinomial coefficients for $k=3$ are odd.
Let $Q(k)$ be the number of odd coefficients in the expansion of $(x^4+x^3+x^2+x+1)^k$.
So $Q(3)=7$.
You are given $Q(10)=17$ and $Q(100)=35$.
Find $\sum_{k=1}^{18}Q(10^k)$. | <p>
The coefficients in the expansion of $(x+1)^k$ are called <strong>binomial coefficients</strong>.<br>
Analoguously the coefficients in the expansion of $(x^4+x^3+x^2+x+1)^k$ are called <strong>quintinomial coefficients</strong>.<br> (quintus= Latin for fifth).
</p>
<p>
Consider the expansion of $(x^4+x^3+x^2+x+1)^3$:<br>
$x^{12}+3x^{11}+6x^{10}+10x^9+15x^8+18x^7+19x^6+18x^5+15x^4+10x^3+6x^2+3x+1$<br>
As we can see $7$ out of the $13$ quintinomial coefficients for $k=3$ are odd.
</p>
<p>
Let $Q(k)$ be the number of odd coefficients in the expansion of $(x^4+x^3+x^2+x+1)^k$.<br>
So $Q(3)=7$.
</p>
<p>
You are given $Q(10)=17$ and $Q(100)=35$.
</p>
<p>Find $\sum_{k=1}^{18}Q(10^k)$.
</p> | https://projecteuler.net/problem=588 | 11651930052 |
589 | Christopher Robin and Pooh Bear love the game of Poohsticks so much that they invented a new version which allows them to play for longer before one of them wins and they have to go home for tea. The game starts as normal with both dropping a stick simultaneously on the upstream side of a bridge. But rather than the game ending when one of the sticks emerges on the downstream side, instead they fish their sticks out of the water, and drop them back in again on the upstream side. The game only ends when one of the sticks emerges from under the bridge ahead of the other one having also 'lapped' the other stick - that is, having made one additional journey under the bridge compared to the other stick.
On a particular day when playing this game, the time taken for a stick to travel under the bridge varies between a minimum of 30 seconds, and a maximum of 60 seconds. The time taken to fish a stick out of the water and drop it back in again on the other side is 5 seconds. The current under the bridge has the unusual property that the sticks' journey time is always an integral number of seconds, and it is equally likely to emerge at any of the possible times between 30 and 60 seconds (inclusive). It turns out that under these circumstances, the expected time for playing a single game is 1036.15 seconds (rounded to 2 decimal places). This time is measured from the point of dropping the sticks for the first time, to the point where the winning stick emerges from under the bridge having lapped the other.
The stream flows at different rates each day, but maintains the property that the journey time in seconds is equally distributed amongst the integers from a minimum, $n$, to a maximum, $m$, inclusive. Let the expected time of play in seconds be $E(m,n)$. Hence $E(60,30)=1036.15...$
Let $S(k)=\sum_{m=2}^k\sum_{n=1}^{m-1}E(m,n)$.
For example $S(5)=7722.82$ rounded to 2 decimal places.
Find $S(100)$ and give your answer rounded to 2 decimal places. | <p>
Christopher Robin and Pooh Bear love the game of Poohsticks so much that they invented a new version which allows them to play for longer before one of them wins and they have to go home for tea. The game starts as normal with both dropping a stick simultaneously on the upstream side of a bridge. But rather than the game ending when one of the sticks emerges on the downstream side, instead they fish their sticks out of the water, and drop them back in again on the upstream side. The game only ends when one of the sticks emerges from under the bridge ahead of the other one having also 'lapped' the other stick - that is, having made one additional journey under the bridge compared to the other stick.
</p>
<p>
On a particular day when playing this game, the time taken for a stick to travel under the bridge varies between a minimum of 30 seconds, and a maximum of 60 seconds. The time taken to fish a stick out of the water and drop it back in again on the other side is 5 seconds. The current under the bridge has the unusual property that the sticks' journey time is always an integral number of seconds, and it is equally likely to emerge at any of the possible times between 30 and 60 seconds (inclusive). It turns out that under these circumstances, the expected time for playing a single game is 1036.15 seconds (rounded to 2 decimal places). This time is measured from the point of dropping the sticks for the first time, to the point where the winning stick emerges from under the bridge having lapped the other.
</p>
<p>
The stream flows at different rates each day, but maintains the property that the journey time in seconds is equally distributed amongst the integers from a minimum, $n$, to a maximum, $m$, inclusive. Let the expected time of play in seconds be $E(m,n)$. Hence $E(60,30)=1036.15...$
</p>
<p>
Let $S(k)=\sum_{m=2}^k\sum_{n=1}^{m-1}E(m,n)$.
</p>
<p>
For example $S(5)=7722.82$ rounded to 2 decimal places.
</p>
<p>
Find $S(100)$ and give your answer rounded to 2 decimal places.
</p> | https://projecteuler.net/problem=589 | 131776959.25 |
590 | Let $H(n)$ denote the number of sets of positive integers such that the least common multiple of the integers in the set equals $n$.
E.g.:
The integers in the following ten sets all have a least common multiple of $6$:
$\{2,3\}$, $\{1,2,3\}$, $\{6\}$, $\{1,6\}$, $\{2,6\}$, $\{1,2,6\}$, $\{3,6\}$, $\{1,3,6\}$, $\{2,3,6\}$ and $\{1,2,3,6\}$.
Thus $H(6)=10$.
Let $L(n)$ denote the least common multiple of the numbers $1$ through $n$.
E.g. $L(6)$ is the least common multiple of the numbers $1,2,3,4,5,6$ and $L(6)$ equals $60$.
Let $HL(n)$ denote $H(L(n))$.
You are given $HL(4)=H(12)=44$.
Find $HL(50000)$. Give your answer modulo $10^9$. | <p>
Let $H(n)$ denote the number of sets of positive integers such that the <strong>least common multiple</strong> of the integers in the set equals $n$.<br>
E.g.:<br>
The integers in the following ten sets all have a least common multiple of $6$:<br>
$\{2,3\}$, $\{1,2,3\}$, $\{6\}$, $\{1,6\}$, $\{2,6\}$, $\{1,2,6\}$, $\{3,6\}$, $\{1,3,6\}$, $\{2,3,6\}$ and $\{1,2,3,6\}$.<br>
Thus $H(6)=10$.
</p>
<p>
Let $L(n)$ denote the least common multiple of the numbers $1$ through $n$.<br>
E.g. $L(6)$ is the least common multiple of the numbers $1,2,3,4,5,6$ and $L(6)$ equals $60$.
</p>
<p>
Let $HL(n)$ denote $H(L(n))$.<br>
You are given $HL(4)=H(12)=44$.
</p>
<p>
Find $HL(50000)$. Give your answer modulo $10^9$.
</p> | https://projecteuler.net/problem=590 | 834171904 |
591 | Given a non-square integer $d$, any real $x$ can be approximated arbitrarily close by quadratic integers $a+b\sqrt{d}$, where $a,b$ are integers. For example, the following inequalities approximate $\pi$ with precision $10^{-13}$:
$$4375636191520\sqrt{2}-6188084046055 < \pi < 721133315582\sqrt{2}-1019836515172 $$
We call $BQA_d(x,n)$ the quadratic integer closest to $x$ with the absolute values of $a,b$ not exceeding $n$.
We also define the integral part of a quadratic integer as $I_d(a+b\sqrt{d}) = a$.
You are given that:
- $BQA_2(\pi,10) = 6 - 2\sqrt{2}$
- $BQA_5(\pi,100)=26\sqrt{5}-55$
- $BQA_7(\pi,10^6)=560323 - 211781\sqrt{7}$
- $I_2(BQA_2(\pi,10^{13}))=-6188084046055$
Find the sum of $|I_d(BQA_d(\pi,10^{13}))|$ for all non-square positive integers less than 100. | <p>Given a non-square integer $d$, any real $x$ can be approximated arbitrarily close by <b>quadratic integers</b> $a+b\sqrt{d}$, where $a,b$ are integers. For example, the following inequalities approximate $\pi$ with precision $10^{-13}$:<br>
$$4375636191520\sqrt{2}-6188084046055 < \pi < 721133315582\sqrt{2}-1019836515172 $$<br>
We call $BQA_d(x,n)$ the quadratic integer closest to $x$ with the absolute values of $a,b$ not exceeding $n$.<br> We also define the integral part of a quadratic integer as $I_d(a+b\sqrt{d}) = a$.</p>
<p>You are given that:</p>
<ul><li>$BQA_2(\pi,10) = 6 - 2\sqrt{2}$</li>
<li>$BQA_5(\pi,100)=26\sqrt{5}-55$</li>
<li>$BQA_7(\pi,10^6)=560323 - 211781\sqrt{7}$</li>
<li>$I_2(BQA_2(\pi,10^{13}))=-6188084046055$</li></ul>
<p>Find the sum of $|I_d(BQA_d(\pi,10^{13}))|$ for all non-square positive integers less than 100.</p> | https://projecteuler.net/problem=591 | 526007984625966 |
592 | For any $N$, let $f(N)$ be the last twelve hexadecimal digits before the trailing zeroes in $N!$.
For example, the hexadecimal representation of $20!$ is 21C3677C82B40000,
so $f(20)$ is the digit sequence 21C3677C82B4.
Find $f(20!)$. Give your answer as twelve hexadecimal digits, using uppercase for the digits A to F. | <p>For any $N$, let $f(N)$ be the last twelve hexadecimal digits before the trailing zeroes in $N!$.</p>
<p>For example, the hexadecimal representation of $20!$ is 21C3677C82B40000,<br>
so $f(20)$ is the digit sequence 21C3677C82B4.</p>
<p>Find $f(20!)$. Give your answer as twelve hexadecimal digits, using uppercase for the digits A to F.</p> | https://projecteuler.net/problem=592 | 13415DF2BE9C |
593 | We define two sequences $S = \{S(1), S(2), ..., S(n)\}$ and $S_2 = \{S_2(1), S_2(2), ..., S_2(n)\}$:
$S(k) = (p_k)^k \bmod 10007$ where $p_k$ is the $k$th prime number.
$S_2(k) = S(k) + S(\lfloor\frac{k}{10000}\rfloor + 1)$ where $\lfloor \cdot \rfloor$ denotes the floor function.
Then let $M(i, j)$ be the median of elements $S_2(i)$ through $S_2(j)$, inclusive. For example, $M(1, 10) = 2021.5$ and $M(10^2, 10^3) = 4715.0$.
Let $F(n, k) = \sum_{i=1}^{n-k+1} M(i, i + k - 1)$. For example, $F(100, 10) = 463628.5$ and $F(10^5, 10^4) = 675348207.5$.
Find $F(10^7, 10^5)$. If the sum is not an integer, use $.5$ to denote a half. Otherwise, use $.0$ instead. | <p>We define two sequences $S = \{S(1), S(2), ..., S(n)\}$ and $S_2 = \{S_2(1), S_2(2), ..., S_2(n)\}$:</p>
<p>$S(k) = (p_k)^k \bmod 10007$ where $p_k$ is the $k$th prime number.</p>
<p>$S_2(k) = S(k) + S(\lfloor\frac{k}{10000}\rfloor + 1)$ where $\lfloor \cdot \rfloor$ denotes the floor function.</p>
<p>Then let $M(i, j)$ be the median of elements $S_2(i)$ through $S_2(j)$, inclusive. For example, $M(1, 10) = 2021.5$ and $M(10^2, 10^3) = 4715.0$.</p>
<p>Let $F(n, k) = \sum_{i=1}^{n-k+1} M(i, i + k - 1)$. For example, $F(100, 10) = 463628.5$ and $F(10^5, 10^4) = 675348207.5$.</p>
<p>Find $F(10^7, 10^5)$. If the sum is not an integer, use $.5$ to denote a half. Otherwise, use $.0$ instead.</p> | https://projecteuler.net/problem=593 | 96632320042.0 |
594 | For a polygon $P$, let $t(P)$ be the number of ways in which $P$ can be tiled using rhombi and squares with edge length 1. Distinct rotations and reflections are counted as separate tilings.
For example, if $O$ is a regular octagon with edge length 1, then $t(O) = 8$. As it happens, all these 8 tilings are rotations of one another:
Let $O_{a,b}$ be the equal-angled convex octagon whose edges alternate in length between $a$ and $b$.
For example, here is $O_{2,1}$, with one of its tilings:
You are given that $t(O_{1,1})=8$, $t(O_{2,1})=76$ and $t(O_{3,2})=456572$.
Find $t(O_{4,2})$. | <p>
For a polygon $P$, let $t(P)$ be the number of ways in which $P$ can be tiled using rhombi and squares with edge length 1. Distinct rotations and reflections are counted as separate tilings.
</p>
<p>
For example, if $O$ is a regular octagon with edge length 1, then $t(O) = 8$. As it happens, all these 8 tilings are rotations of one another:
</p>
<div class="center">
<img src="resources/images/0594_octagon_tilings_1.png?1678992053" alt="0594_octagon_tilings_1.png">
</div>
<p>
Let $O_{a,b}$ be the equal-angled convex octagon whose edges alternate in length between $a$ and $b$.
<br>
For example, here is $O_{2,1}$, with one of its tilings:
</p>
<div class="center">
<img src="resources/images/0594_octagon_tilings_2.png?1678992053" alt="0594_octagon_tilings_2.png">
</div>
<p>
You are given that $t(O_{1,1})=8$, $t(O_{2,1})=76$ and $t(O_{3,2})=456572$.
</p>
<p>
Find $t(O_{4,2})$.
</p> | https://projecteuler.net/problem=594 | 47067598 |
595 | A deck of cards numbered from $1$ to $n$ is shuffled randomly such that each permutation is equally likely.
The cards are to be sorted into ascending order using the following technique:
- Look at the initial sequence of cards. If it is already sorted, then there is no need for further action. Otherwise, if any subsequences of cards happen to be in the correct place relative to one another (ascending with no gaps), then those subsequences are fixed by attaching the cards together. For example, with $7$ cards initially in the order 4123756, the cards labelled 1, 2 and 3 would be attached together, as would 5 and 6.
- The cards are 'shuffled' by being thrown into the air, but note that any correctly sequenced cards remain attached, so their orders are maintained. The cards (or bundles of attached cards) are then picked up randomly. You should assume that this randomisation is unbiased, despite the fact that some cards are single, and others are grouped together.
- Repeat steps 1 and 2 until the cards are sorted.
Let $S(n)$ be the expected number of shuffles needed to sort the cards. Since the order is checked before the first shuffle, $S(1) = 0$. You are given that $S(2) = 1$, and $S(5) = 4213/871$.
Find $S(52)$, and give your answer rounded to $8$ decimal places. | <p>
A deck of cards numbered from $1$ to $n$ is shuffled randomly such that each permutation is equally likely.
</p>
<p>
The cards are to be sorted into ascending order using the following technique:
</p><ol>
<li> Look at the initial sequence of cards. If it is already sorted, then there is no need for further action. Otherwise, if any subsequences of cards happen to be in the correct place relative to one another (ascending with no gaps), then those subsequences are fixed by attaching the cards together. For example, with $7$ cards initially in the order 4123756, the cards labelled 1, 2 and 3 would be attached together, as would 5 and 6.
</li></ol>
<ol start="2">
<li> The cards are 'shuffled' by being thrown into the air, but note that any correctly sequenced cards remain attached, so their orders are maintained. The cards (or bundles of attached cards) are then picked up randomly. You should assume that this randomisation is unbiased, despite the fact that some cards are single, and others are grouped together.
</li></ol>
<ol start="3">
<li> Repeat steps 1 and 2 until the cards are sorted.
</li></ol>
<p>
Let $S(n)$ be the expected number of shuffles needed to sort the cards. Since the order is checked before the first shuffle, $S(1) = 0$. You are given that $S(2) = 1$, and $S(5) = 4213/871$.
</p>
<p>
Find $S(52)$, and give your answer rounded to $8$ decimal places.
</p> | https://projecteuler.net/problem=595 | 54.17529329 |
596 | Let $T(r)$ be the number of integer quadruplets $x, y, z, t$ such that $x^2 + y^2 + z^2 + t^2 \le r^2$. In other words, $T(r)$ is the number of lattice points in the four-dimensional hyperball of radius $r$.
You are given that $T(2) = 89$, $T(5) = 3121$, $T(100) = 493490641$ and $T(10^4) = 49348022079085897$.
Find $T(10^8) \bmod 1000000007$. | <p>Let $T(r)$ be the number of integer quadruplets $x, y, z, t$ such that $x^2 + y^2 + z^2 + t^2 \le r^2$. In other words, $T(r)$ is the number of lattice points in the four-dimensional hyperball of radius $r$.</p>
<p>You are given that $T(2) = 89$, $T(5) = 3121$, $T(100) = 493490641$ and $T(10^4) = 49348022079085897$.</p>
<p>Find $T(10^8) \bmod 1000000007$.</p> | https://projecteuler.net/problem=596 | 734582049 |
597 | The Torpids are rowing races held annually in Oxford, following some curious rules:
-
A division consists of $n$ boats (typically 13), placed in order based on past performance.
-
All boats within a division start at 40 metre intervals along the river, in order with the highest-placed boat starting furthest upstream.
-
The boats all start rowing simultaneously, upstream, trying to catch the boat in front while avoiding being caught by boats behind.
-
Each boat continues rowing until either it reaches the finish line or it catches up with ("bumps") a boat in front.
-
The finish line is a distance $L$ metres (the course length, in reality about 1800 metres) upstream from the starting position of the lowest-placed boat. (Because of the staggered starting positions, higher-placed boats row a slightly shorter course than lower-placed boats.)
-
When a "bump" occurs, the "bumping" boat takes no further part in the race. The "bumped" boat must continue, however, and may even be "bumped" again by boats that started two or more places behind it.
-
After the race, boats are assigned new places within the division, based on the bumps that occurred. Specifically, for any boat $A$ that started in a lower place than $B$, then $A$ will be placed higher than $B$ in the new order if and only if one of the following occurred:
- $A$ bumped $B$ directly
- $A$ bumped another boat that went on to bump $B$
- $A$ bumped another boat, that bumped yet another boat, that bumped $B$
- etc
NOTE: For the purposes of this problem you may disregard the boats' lengths, and assume that a bump occurs precisely when the two boats draw level. (In reality, a bump is awarded as soon as physical contact is made, which usually occurs when there is much less than a full boat length's overlap.)
Suppose that, in a particular race, each boat $B_j$ rows at a steady speed $v_j = -$log$X_j$ metres per second, where the $X_j$ are chosen randomly (with uniform distribution) between 0 and 1, independently from one another. These speeds are relative to the riverbank: you may disregard the flow of the river.
Let $p(n,L)$ be the probability that the new order is an even permutation of the starting order, when there are $n$ boats in the division and $L$ is the course length.
For example, with $n=3$ and $L=160$, labelling the boats as $A$,$B$,$C$ in starting order with $C$ highest, the different possible outcomes of the race are as follows:
| Bumps occurring | New order | Permutation | Probability |
| --- | --- | --- | --- |
| none | $A$, $B$, $C$ | even | $4/15$ |
| $B$ bumps $C$ | $A$, $C$, $B$ | odd | $8/45$ |
| $A$ bumps $B$ | $B$, $A$, $C$ | odd | $1/3$ |
| $B$ bumps $C$, then $A$ bumps $C$ | $C$, $A$, $B$ | even | $4/27$ |
| $A$ bumps $B$, then $B$ bumps $C$ | $C$, $B$, $A$ | odd | $2/27$ |
Therefore, $p(3,160) = 4/15 + 4/27 = 56/135$.
You are also given that $p(4,400)=0.5107843137$, rounded to 10 digits after the decimal point.
Find $p(13,1800)$ rounded to 10 digits after the decimal point. | The Torpids are rowing races held annually in Oxford, following some curious rules:
<ul>
<li>
A division consists of $n$ boats (typically 13), placed in order based on past performance.
</li><li>
All boats within a division start at 40 metre intervals along the river, in order with the highest-placed boat starting furthest upstream.
</li><li>
The boats all start rowing simultaneously, upstream, trying to catch the boat in front while avoiding being caught by boats behind.
</li><li>
Each boat continues rowing until <em>either</em> it reaches the finish line <em>or</em> it catches up with ("bumps") a boat in front.
</li><li>
The finish line is a distance $L$ metres (the course length, in reality about 1800 metres) upstream from the starting position of the lowest-placed boat. (Because of the staggered starting positions, higher-placed boats row a slightly shorter course than lower-placed boats.)
</li><li>
When a "bump" occurs, the "bumping" boat takes no further part in the race. The "bumped" boat must continue, however, and may even be "bumped" again by boats that started two or more places behind it.
</li><li>
After the race, boats are assigned new places within the division, based on the bumps that occurred. Specifically, for any boat $A$ that started in a lower place than $B$, then $A$ will be placed higher than $B$ in the new order if and only if one of the following occurred:
<ol>
<li> $A$ bumped $B$ directly </li>
<li> $A$ bumped another boat that went on to bump $B$ </li>
<li> $A$ bumped another boat, that bumped yet another boat, that bumped $B$ </li>
<li> etc </li></ol>
</li></ul>
<b>NOTE</b>: For the purposes of this problem you may disregard the boats' lengths, and assume that a bump occurs precisely when the two boats draw level. (In reality, a bump is awarded as soon as physical contact is made, which usually occurs when there is much less than a full boat length's overlap.)
<p>
Suppose that, in a particular race, each boat $B_j$ rows at a steady speed $v_j = -$log$X_j$ metres per second, where the $X_j$ are chosen randomly (with uniform distribution) between 0 and 1, independently from one another. These speeds are relative to the riverbank: you may disregard the flow of the river.
</p>
<p>
Let $p(n,L)$ be the probability that the new order is an <b>even permutation</b> of the starting order, when there are $n$ boats in the division and $L$ is the course length.
</p>
<p>
For example, with $n=3$ and $L=160$, labelling the boats as $A$,$B$,$C$ in starting order with $C$ highest, the different possible outcomes of the race are as follows:
</p>
<table cellspacing="15" align="center">
<tr>
<th> Bumps occurring </th>
<th> New order </th>
<th> Permutation </th>
<th> Probability </th>
</tr>
<tr align="center">
<td> none </td>
<td> $A$, $B$, $C$ </td>
<td> even </td>
<td> $4/15$ </td>
</tr>
<tr align="center">
<td> $B$ bumps $C$ </td>
<td> $A$, $C$, $B$ </td>
<td> odd </td>
<td> $8/45$ </td>
</tr>
<tr align="center">
<td> $A$ bumps $B$ </td>
<td> $B$, $A$, $C$ </td>
<td> odd </td>
<td> $1/3$ </td>
</tr>
<tr align="center">
<td> $B$ bumps $C$, then $A$ bumps $C$ </td>
<td> $C$, $A$, $B$ </td>
<td> even </td>
<td> $4/27$ </td>
</tr>
<tr align="center">
<td> $A$ bumps $B$, then $B$ bumps $C$ </td>
<td> $C$, $B$, $A$ </td>
<td> odd </td>
<td> $2/27$ </td>
</tr>
</table>
<p>
Therefore, $p(3,160) = 4/15 + 4/27 = 56/135$.
</p>
<p>
You are also given that $p(4,400)=0.5107843137$, rounded to 10 digits after the decimal point.
</p>
<p>
Find $p(13,1800)$ rounded to 10 digits after the decimal point.
</p> | https://projecteuler.net/problem=597 | 0.5001817828 |
598 | Consider the number $48$.
There are five pairs of integers $a$ and $b$ ($a \leq b$) such that $a \times b=48$: $(1,48)$, $(2,24)$, $(3,16)$, $(4,12)$ and $(6,8)$.
It can be seen that both $6$ and $8$ have $4$ divisors.
So of those five pairs one consists of two integers with the same number of divisors.
In general:
Let $C(n)$ be the number of pairs of positive integers $a \times b=n$, ($a \leq b$) such that $a$ and $b$ have the same number of divisors;
so $C(48)=1$.
You are given $C(10!)=3$: $(1680, 2160)$, $(1800, 2016)$ and $(1890,1920)$.
Find $C(100!)$. | <p>
Consider the number $48$.<br>
There are five pairs of integers $a$ and $b$ ($a \leq b$) such that $a \times b=48$: $(1,48)$, $(2,24)$, $(3,16)$, $(4,12)$ and $(6,8)$.<br>
It can be seen that both $6$ and $8$ have $4$ divisors.<br>
So of those five pairs one consists of two integers with the same number of divisors.</p>
<p>
In general:<br>
Let $C(n)$ be the number of pairs of positive integers $a \times b=n$, ($a \leq b$) such that $a$ and $b$ have the same number of divisors; <br>so $C(48)=1$.
</p>
<p>
You are given $C(10!)=3$: $(1680, 2160)$, $(1800, 2016)$ and $(1890,1920)$.</p><p>
Find $C(100!)$.</p> | https://projecteuler.net/problem=598 | 543194779059 |
599 | The well-known Rubik's Cube puzzle has many fascinating mathematical properties. The 2×2×2 variant has 8 cubelets with a total of 24 visible faces, each with a coloured sticker. Successively turning faces will rearrange the cubelets, although not all arrangements of cubelets are reachable without dismantling the puzzle.
Suppose that we wish to apply new stickers to a 2×2×2 Rubik's cube in a non-standard colouring. Specifically, we have $n$ different colours available (with an unlimited supply of stickers of each colour), and we place one sticker on each of the 24 faces in any arrangement that we please. We are not required to use all the colours, and if desired the same colour may appear in more than one face of a single cubelet.
We say that two such colourings $c_1,c_2$ are essentially distinct if a cube coloured according to $c_1$ cannot be made to match a cube coloured according to $c_2$ by performing mechanically possible Rubik's Cube moves.
For example, with two colours available, there are 183 essentially distinct colourings.
How many essentially distinct colourings are there with 10 different colours available? | <p>
The well-known <strong>Rubik's Cube</strong> puzzle has many fascinating mathematical properties. The 2×2×2 variant has 8 cubelets with a total of 24 visible faces, each with a coloured sticker. Successively turning faces will rearrange the cubelets, although not all arrangements of cubelets are reachable without dismantling the puzzle.
</p>
<p>
Suppose that we wish to apply new stickers to a 2×2×2 Rubik's cube in a non-standard colouring. Specifically, we have $n$ different colours available (with an unlimited supply of stickers of each colour), and we place one sticker on each of the 24 faces in any arrangement that we please. We are not required to use all the colours, and if desired the same colour may appear in more than one face of a single cubelet.
</p>
<p>
We say that two such colourings $c_1,c_2$ are <em>essentially distinct</em> if a cube coloured according to $c_1$ cannot be made to match a cube coloured according to $c_2$ by performing mechanically possible Rubik's Cube moves.
</p>
<p>
For example, with two colours available, there are 183 essentially distinct colourings.
</p>
<p>
How many essentially distinct colourings are there with 10 different colours available?
</p> | https://projecteuler.net/problem=599 | 12395526079546335 |
600 | Let $H(n)$ be the number of distinct integer sided equiangular convex hexagons with perimeter not exceeding $n$.
Hexagons are distinct if and only if they are not congruent.
You are given $H(6) = 1$, $H(12) = 10$, $H(100) = 31248$.
Find $H(55106)$.
Equiangular hexagons with perimeter not exceeding $12$ | <p>Let $H(n)$ be the number of distinct integer sided <strong>equiangular</strong> convex hexagons with perimeter not exceeding $n$.<br>
Hexagons are distinct if and only if they are not <strong>congruent</strong>.</p>
<p>You are given $H(6) = 1$, $H(12) = 10$, $H(100) = 31248$.<br>
Find $H(55106)$.</p>
<div class="center">
<img src="resources/images/0600_equiangular_hexagons.png?1678992054" alt="p600-equiangular-hexagons.png" border="5">
<p><i>Equiangular hexagons with perimeter not exceeding $12$</i></p>
</div> | https://projecteuler.net/problem=600 | 2668608479740672 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.