id
int64
1
981
problem
stringlengths
97
5.29k
raw_html
stringlengths
121
5.63k
url
stringlengths
34
36
answer
stringlengths
1
29
901
A driller drills for water. At each iteration the driller chooses a depth $d$ (a positive real number), drills to this depth and then checks if water was found. If so, the process terminates. Otherwise, a new depth is chosen and a new drilling starts from the ground level in a new location nearby. Drilling to depth $d$ takes exactly $d$ hours. The groundwater depth is constant in the relevant area and its distribution is known to be an exponential random variable with expected value of $1$. In other words, the probability that the groundwater is deeper than $d$ is $e^{-d}$. Assuming an optimal strategy, find the minimal expected drilling time in hours required to find water. Give your answer rounded to 9 places after the decimal point.
<p>A driller drills for water. At each iteration the driller chooses a depth $d$ (a positive real number), drills to this depth and then checks if water was found. If so, the process terminates. Otherwise, a new depth is chosen and a new drilling starts from the ground level in a new location nearby.</p> <p>Drilling to depth $d$ takes exactly $d$ hours. The groundwater depth is constant in the relevant area and its distribution is known to be an <a href="https://en.wikipedia.org/wiki/Exponential_distribution">exponential random variable</a> with expected value of $1$. In other words, the probability that the groundwater is deeper than $d$ is $e^{-d}$.</p> <p>Assuming an optimal strategy, find the minimal expected drilling time in hours required to find water. Give your answer rounded to 9 places after the decimal point.</p>
https://projecteuler.net/problem=901
2.364497769
902
A permutation $\pi$ of $\{1, \dots, n\}$ can be represented in one-line notation as $\pi(1),\ldots,\pi(n) $. If all $n!$ permutations are written in lexicographic order then $\textrm{rank}(\pi)$ is the position of $\pi$ in this 1-based list. For example, $\text{rank}(2,1,3) = 3$ because the six permutations of $\{1, 2, 3\}$ in lexicographic order are: $$1, 2, 3\quad 1, 3, 2 \quad 2, 1, 3 \quad 2, 3, 1 \quad 3, 1, 2 \quad 3, 2, 1$$ For a positive integer $m$, we define the following permutation of $\{1, \dots, n\}$ with $n = \frac{m(m+1)}2$: $$ \begin{align} \sigma(i) &= \begin{cases} \frac{k(k-1)}2 + 1 & \textrm{if } i = \frac{k(k + 1)}2\textrm{ for }k\in\{1, \dots, m\};\\i + 1 & \textrm{otherwise};\end{cases}\\ \tau(i) &= ((10^9 + 7)i \bmod n) + 1\\ \pi(i) &= \tau^{-1}(\sigma(\tau(i))) \end{align} $$ where $\tau^{-1}$ is the inverse permutation of $\tau$. Define $\displaystyle P(m) = \sum_{k=1}^{m!} \text{rank}(\pi^k)$, where $\pi^k$ is the permutation arising from applying $\pi$ $k$ times. For example, $P(2) = 4$, $P(3) = 780$ and $P(4) = 38810300$. Find $P(100)$. Give your answer modulo $(10^9 + 7)$.
<p>A permutation $\pi$ of $\{1, \dots, n\}$ can be represented in <b>one-line notation</b> as $\pi(1),\ldots,\pi(n) $. If all $n!$ permutations are written in lexicographic order then $\textrm{rank}(\pi)$ is the position of $\pi$ in this 1-based list.</p> <p>For example, $\text{rank}(2,1,3) = 3$ because the six permutations of $\{1, 2, 3\}$ in lexicographic order are: $$1, 2, 3\quad 1, 3, 2 \quad 2, 1, 3 \quad 2, 3, 1 \quad 3, 1, 2 \quad 3, 2, 1$$ </p> <p>For a positive integer $m$, we define the following permutation of $\{1, \dots, n\}$ with $n = \frac{m(m+1)}2$: $$ \begin{align} \sigma(i) &amp;= \begin{cases} \frac{k(k-1)}2 + 1 &amp; \textrm{if } i = \frac{k(k + 1)}2\textrm{ for }k\in\{1, \dots, m\};\\i + 1 &amp; \textrm{otherwise};\end{cases}\\ \tau(i) &amp;= ((10^9 + 7)i \bmod n) + 1\\ \pi(i) &amp;= \tau^{-1}(\sigma(\tau(i))) \end{align} $$ where $\tau^{-1}$ is the inverse permutation of $\tau$. </p> <p>Define $\displaystyle P(m) = \sum_{k=1}^{m!} \text{rank}(\pi^k)$, where $\pi^k$ is the permutation arising from applying $\pi$ $k$ times.<br> For example, $P(2) = 4$, $P(3) = 780$ and $P(4) = 38810300$.</p> <p> Find $P(100)$. Give your answer modulo $(10^9 + 7)$. </p>
https://projecteuler.net/problem=902
343557869
903
A permutation $\pi$ of $\{1, \dots, n\}$ can be represented in one-line notation as $\pi(1),\ldots,\pi(n) $. If all $n!$ permutations are written in lexicographic order then $\textrm{rank}(\pi)$ is the position of $\pi$ in this 1-based list. For example, $\text{rank}(2,1,3) = 3$ because the six permutations of $\{1, 2, 3\}$ in lexicographic order are: $$1, 2, 3\quad 1, 3, 2 \quad 2, 1, 3 \quad 2, 3, 1 \quad 3, 1, 2 \quad 3, 2, 1$$ Let $Q(n)$ be the sum $\sum_{\pi}\sum_{i = 1}^{n!} \text{rank}(\pi^i)$, where $\pi$ ranges over all permutations of $\{1, \dots, n\}$, and $\pi^i$ is the permutation arising from applying $\pi$ $i$ times. For example, $Q(2) = 5$, $Q(3) = 88$, $Q(6) = 133103808$ and $Q(10) \equiv 468421536 \pmod {10^9 + 7}$. Find $Q(10^6)$. Give your answer modulo $(10^9 + 7)$.
<p>A permutation $\pi$ of $\{1, \dots, n\}$ can be represented in <b>one-line notation</b> as $\pi(1),\ldots,\pi(n) $. If all $n!$ permutations are written in lexicographic order then $\textrm{rank}(\pi)$ is the position of $\pi$ in this 1-based list.</p> <p>For example, $\text{rank}(2,1,3) = 3$ because the six permutations of $\{1, 2, 3\}$ in lexicographic order are: $$1, 2, 3\quad 1, 3, 2 \quad 2, 1, 3 \quad 2, 3, 1 \quad 3, 1, 2 \quad 3, 2, 1$$ </p> <p>Let $Q(n)$ be the sum $\sum_{\pi}\sum_{i = 1}^{n!} \text{rank}(\pi^i)$, where $\pi$ ranges over all permutations of $\{1, \dots, n\}$, and $\pi^i$ is the permutation arising from applying $\pi$ $i$ times.</p> <p>For example, $Q(2) = 5$, $Q(3) = 88$, $Q(6) = 133103808$ and $Q(10) \equiv 468421536 \pmod {10^9 + 7}$.</p> <p>Find $Q(10^6)$. Give your answer modulo $(10^9 + 7)$.</p>
https://projecteuler.net/problem=903
128553191
904
Given a right-angled triangle with integer sides, the smaller angle formed by the two medians drawn on the the two perpendicular sides is denoted by $\theta$. Let $f(\alpha, L)$ denote the sum of the sides of the right-angled triangle minimizing the absolute difference between $\theta$ and $\alpha$ among all right-angled triangles with integer sides and hypotenuse not exceeding $L$. If more than one triangle attains the minimum value, the triangle with the maximum area is chosen. All angles in this problem are measured in degrees. For example, $f(30,10^2)=198$ and $f(10,10^6)= 1600158$. Define $F(N,L)=\sum_{n=1}^{N}f\left(\sqrt[3]{n},L\right)$. You are given $F(10,10^6)= 16684370$. Find $F(45000, 10^{10})$.
<p>Given a right-angled triangle with integer sides, the smaller angle formed by the two medians drawn on the the two perpendicular sides is denoted by $\theta$. </p> <div style="text-align:center;"><img src="resources/images/0904_pythagorean_angle.png?1723895050" alt="0904_Pythagorean_angle.jpg"></div> <p>Let $f(\alpha, L)$ denote the sum of the sides of the right-angled triangle minimizing the absolute difference between $\theta$ and $\alpha$ among all right-angled triangles with integer sides and hypotenuse not exceeding $L$.<br>If more than one triangle attains the minimum value, the triangle with the maximum area is chosen. All angles in this problem are measured in degrees. </p> <p> For example, $f(30,10^2)=198$ and $f(10,10^6)= 1600158$. </p> <p> Define $F(N,L)=\sum_{n=1}^{N}f\left(\sqrt[3]{n},L\right)$.<br>You are given $F(10,10^6)= 16684370$.</p> <p> Find $F(45000, 10^{10})$.</p>
https://projecteuler.net/problem=904
880652522278760
905
Three epistemologists, known as A, B, and C, are in a room, each wearing a hat with a number on it. They have been informed beforehand that all three numbers are positive and that one of the numbers is the sum of the other two. Once in the room, they can see the numbers on each other's hats but not on their own. Starting with A and proceeding cyclically, each epistemologist must either honestly state "I don't know my number" or announce "Now I know my number!" which terminates the game. For instance, if their numbers are $A=2, B=1, C=1$ then A declares "Now I know" at the first turn. If their numbers are $A=2, B=7, C=5$ then "I don't know" is heard four times before B finally declares "Now I know" at the fifth turn. Let $F(A,B,C)$ be the number of turns it takes until an epistemologist declares "Now I know", including the turn this declaration is made. So $F(2,1,1)=1$ and $F(2,7,5)=5$. Find $\displaystyle \sum_{a=1}^7 \sum_{b=1}^{19} F(a^b, b^a, a^b + b^a)$.
<p> Three epistemologists, known as A, B, and C, are in a room, each wearing a hat with a number on it. They have been informed beforehand that all three numbers are positive and that one of the numbers is the sum of the other two.</p> <p> Once in the room, they can see the numbers on each other's hats but not on their own. Starting with A and proceeding cyclically, each epistemologist must either honestly state "I don't know my number" or announce "Now I know my number!" which terminates the game.</p> <p> For instance, if their numbers are $A=2, B=1, C=1$ then A declares "Now I know" at the first turn. If their numbers are $A=2, B=7, C=5$ then "I don't know" is heard four times before B finally declares "Now I know" at the fifth turn.</p> <p> Let $F(A,B,C)$ be the number of turns it takes until an epistemologist declares "Now I know", including the turn this declaration is made. So $F(2,1,1)=1$ and $F(2,7,5)=5$.</p> <p> Find $\displaystyle \sum_{a=1}^7 \sum_{b=1}^{19} F(a^b, b^a, a^b + b^a)$.</p>
https://projecteuler.net/problem=905
70228218
906
Three friends attempt to collectively choose one of $n$ options, labeled $1,\dots,n$, based upon their individual preferences. They choose option $i$ if for every alternative option $j$ at least two of the three friends prefer $i$ over $j$. If no such option $i$ exists they fail to reach an agreement. Define $P(n)$ to be the probability the three friends successfully reach an agreement and choose one option, where each of the friends' individual order of preference is given by a (possibly different) random permutation of $1,\dots,n$. You are given $P(3)=17/18$ and $P(10)\approx0.6760292265$. Find $P(20\,000)$. Give your answer rounded to ten places after the decimal point.
<p> Three friends attempt to collectively choose one of $n$ options, labeled $1,\dots,n$, based upon their individual preferences. They choose option $i$ if for every alternative option $j$ at least two of the three friends prefer $i$ over $j$. If no such option $i$ exists they fail to reach an agreement. </p> <p> Define $P(n)$ to be the probability the three friends successfully reach an agreement and choose one option, where each of the friends' individual order of preference is given by a (possibly different) random permutation of $1,\dots,n$. </p> <p> You are given $P(3)=17/18$ and $P(10)\approx0.6760292265$. </p> <p> Find $P(20\,000)$. Give your answer rounded to ten places after the decimal point. </p>
https://projecteuler.net/problem=906
0.0195868911
907
An infant's toy consists of $n$ cups, labelled $C_1,\dots,C_n$ in increasing order of size. The cups may be stacked in various combinations and orientations to form towers. The cups are shaped such that the following means of stacking are possible: - Nesting: $C_k$ may sit snugly inside $C_{k+1}$. - Base-to-base: $C_{k+2}$ or $C_{k-2}$ may sit, right-way-up, on top of an up-side-down $C_k$, with their bottoms fitting together snugly. - Rim-to-rim: $C_{k+2}$ or $C_{k-2}$ may sit, up-side-down, on top of a right-way-up $C_k$, with their tops fitting together snugly. - For the purposes of this problem, it is not permitted to stack both $C_{k+2}$ and $C_{k-2}$ rim-to-rim on top of $C_k$, despite the schematic diagrams appearing to allow it: Define $S(n)$ to be the number of ways to build a single tower using all $n$ cups according to the above rules. You are given $S(4)=12$, $S(8)=58$, and $S(20)=5560$. Find $S(10^7)$, giving your answer modulo $1\,000\,000\,007$.
<p> An infant's toy consists of $n$ cups, labelled $C_1,\dots,C_n$ in increasing order of size. </p> <img src="resources/images/0907_four_cups.png?1723769212" alt="0907_four_cups.png" height="162"> <p> The cups may be stacked in various combinations and orientations to form towers. The cups are shaped such that the following means of stacking are possible: </p> <ul> <li>Nesting: $C_k$ may sit snugly inside $C_{k+1}$.<br> <img src="resources/images/0907_nesting.png?1723769266" alt="0907_nesting.png" height="150"> </li> <li>Base-to-base: $C_{k+2}$ or $C_{k-2}$ may sit, right-way-up, on top of an up-side-down $C_k$, with their bottoms fitting together snugly.<br> <img src="resources/images/0907_base_to_base.png?1723769276" alt="0907_base_to_base.png" height="198"> </li> <li>Rim-to-rim: $C_{k+2}$ or $C_{k-2}$ may sit, up-side-down, on top of a right-way-up $C_k$, with their tops fitting together snugly.<br> <img src="resources/images/0907_rim_to_rim.png?1723769283" alt="0907_rim_to_rim.png" height="198"> </li> <li>For the purposes of this problem, it is <b>not</b> permitted to stack <b>both</b> $C_{k+2}$ and $C_{k-2}$ rim-to-rim on top of $C_k$, despite the schematic diagrams appearing to allow it:<br> <img src="resources/images/0907_rim_to_rim_counter_example.png?1740699245" alt="0907_rim_to_rim_counter_example.png" height="267"><br> </li></ul> <p> Define $S(n)$ to be the number of ways to build a single tower using all $n$ cups according to the above rules.<br> You are given $S(4)=12$, $S(8)=58$, and $S(20)=5560$. </p> <p> Find $S(10^7)$, giving your answer modulo $1\,000\,000\,007$. </p>
https://projecteuler.net/problem=907
196808901
908
A clock sequence is a periodic sequence of positive integers that can be broken into contiguous segments such that the sum of the $n$-th segment is equal to $n$. For example, the sequence $$1\ 2\ 3\ 4\ 3\ 2\ 1\ 2\ 3\ 4\ 3\ 2\ 1\ 2\ 3\ 4\ 3\ 2\ 1\ \cdots$$ is a clock sequence with period $6$, as it can be broken into $$1\Big |2\Big |3\Big |4\Big |3\ 2\Big |1\ 2\ 3\Big |4\ 3\Big |2\ 1\ 2\ 3\Big |4\ 3\ 2\Big |1\ 2\ 3\ 4\Big |3\ 2\ 1\ 2\ 3\Big |\cdots$$ Let $C(N)$ be the number of different clock sequences with period at most $N$. For example, $C(3) = 3$, $C(4) = 7$ and $C(10) = 561$. Find $C(10^4) \bmod 1111211113$.
<p> A <dfn>clock sequence</dfn> is a periodic sequence of positive integers that can be broken into contiguous segments such that the sum of the $n$-th segment is equal to $n$.</p> <p> For example, the sequence $$1\ 2\ 3\ 4\ 3\ 2\ 1\ 2\ 3\ 4\ 3\ 2\ 1\ 2\ 3\ 4\ 3\ 2\ 1\ \cdots$$ is a clock sequence with period $6$, as it can be broken into $$1\Big |2\Big |3\Big |4\Big |3\ 2\Big |1\ 2\ 3\Big |4\ 3\Big |2\ 1\ 2\ 3\Big |4\ 3\ 2\Big |1\ 2\ 3\ 4\Big |3\ 2\ 1\ 2\ 3\Big |\cdots$$ Let $C(N)$ be the number of different clock sequences with period at most $N$. For example, $C(3) = 3$, $C(4) = 7$ and $C(10) = 561$.</p> <p> Find $C(10^4) \bmod 1111211113$.</p>
https://projecteuler.net/problem=908
451822602
909
An L-expression is defined as any one of the following: - a natural number; - the symbol $A$; - the symbol $Z$; - the symbol $S$; - a pair of L-expressions $u, v$, which is written as $u(v)$. An L-expression can be transformed according to the following rules: - $A(x) \to x + 1$ for any natural number $x$; - $Z(u)(v) \to v$ for any L-expressions $u, v$; - $S(u)(v)(w) \to v(u(v)(w))$ for any L-expressions $u, v, w$. For example, after applying all possible rules, the L-expression $S(Z)(A)(0)$ is transformed to the number $1$: $$S(Z)(A)(0) \to A(Z(A)(0)) \to A(0) \to 1.$$ Similarly, the L-expression $S(S)(S(S))(S(Z))(A)(0)$ is transformed to the number $6$ after applying all possible rules. Find the result of the L-expression $S(S)(S(S))(S(S))(S(Z))(A)(0)$ after applying all possible rules. Give the last nine digits as your answer. Note: it can be proved that the L-expression in question can only be transformed a finite number of times, and the final result does not depend on the order of the transformations.
<p> An <dfn>L-expression</dfn> is defined as any one of the following:</p> <ul> <li>a natural number;</li> <li>the symbol $A$;</li> <li>the symbol $Z$;</li> <li>the symbol $S$;</li> <li>a pair of L-expressions $u, v$, which is written as $u(v)$.</li> </ul> <p> An L-expression can be transformed according to the following rules:</p> <ul> <li>$A(x) \to x + 1$ for any natural number $x$;</li> <li>$Z(u)(v) \to v$ for any L-expressions $u, v$;</li> <li>$S(u)(v)(w) \to v(u(v)(w))$ for any L-expressions $u, v, w$.</li> </ul> <p> For example, after applying all possible rules, the L-expression $S(Z)(A)(0)$ is transformed to the number $1$: $$S(Z)(A)(0) \to A(Z(A)(0)) \to A(0) \to 1.$$ Similarly, the L-expression $S(S)(S(S))(S(Z))(A)(0)$ is transformed to the number $6$ after applying all possible rules.</p> <p> Find the result of the L-expression $S(S)(S(S))(S(S))(S(Z))(A)(0)$ after applying all possible rules. Give the last nine digits as your answer.</p> <p class="note"><b>Note:</b> it can be proved that the L-expression in question can only be transformed a finite number of times, and the final result does not depend on the order of the transformations.</p>
https://projecteuler.net/problem=909
399885292
910
An L-expression is defined as any one of the following: - a natural number; - the symbol $A$; - the symbol $Z$; - the symbol $S$; - a pair of L-expressions $u, v$, which is written as $u(v)$. An L-expression can be transformed according to the following rules: - $A(x) \to x + 1$ for any natural number $x$; - $Z(u)(v) \to v$ for any L-expressions $u, v$; - $S(u)(v)(w) \to v(u(v)(w))$ for any L-expressions $u, v, w$. For example, after applying all possible rules, the L-expression $S(Z)(A)(0)$ is transformed to the number $1$: $$S(Z)(A)(0) \to A(Z(A)(0)) \to A(0) \to 1.$$ Similarly, the L-expression $S(S)(S(S))(S(Z))(A)(0)$ is transformed to the number $6$ after applying all possible rules. Define the following L-expressions: - $C_0 = Z$; - $C_i = S(C_{i - 1})$ for $i \ge 1$; - $D_i = C_i(S)(S)$. For natural numbers $a, b, c, d, e$, let $F(a, b, c, d, e)$ denote the result of the L-expression $D_a(D_b)(D_c)(C_d)(A)(e)$ after applying all possible rules. Find the last nine digits of $F(12, 345678, 9012345, 678, 90)$. Note: it can be proved that the L-expression in question can only be transformed a finite number of times, and the final result does not depend on the order of the transformations.
<p> An <dfn>L-expression</dfn> is defined as any one of the following:</p> <ul> <li>a natural number;</li> <li>the symbol $A$;</li> <li>the symbol $Z$;</li> <li>the symbol $S$;</li> <li>a pair of L-expressions $u, v$, which is written as $u(v)$.</li> </ul> <p> An L-expression can be transformed according to the following rules:</p> <ul> <li>$A(x) \to x + 1$ for any natural number $x$;</li> <li>$Z(u)(v) \to v$ for any L-expressions $u, v$;</li> <li>$S(u)(v)(w) \to v(u(v)(w))$ for any L-expressions $u, v, w$.</li> </ul> <p> For example, after applying all possible rules, the L-expression $S(Z)(A)(0)$ is transformed to the number $1$: $$S(Z)(A)(0) \to A(Z(A)(0)) \to A(0) \to 1.$$ Similarly, the L-expression $S(S)(S(S))(S(Z))(A)(0)$ is transformed to the number $6$ after applying all possible rules.</p> <p> Define the following L-expressions:</p> <ul> <li>$C_0 = Z$;</li> <li>$C_i = S(C_{i - 1})$ for $i \ge 1$;</li> <li>$D_i = C_i(S)(S)$.</li> </ul> <p> For natural numbers $a, b, c, d, e$, let $F(a, b, c, d, e)$ denote the result of the L-expression $D_a(D_b)(D_c)(C_d)(A)(e)$ after applying all possible rules.</p> <p> Find the last nine digits of $F(12, 345678, 9012345, 678, 90)$.</p> <p class="note"><b>Note:</b> it can be proved that the L-expression in question can only be transformed a finite number of times, and the final result does not depend on the order of the transformations.</p>
https://projecteuler.net/problem=910
547480666
911
An irrational number $x$ can be uniquely expressed as a continued fraction $[a_0; a_1,a_2,a_3,\dots]$: $$ x=a_{0}+\cfrac{1}{a_1+\cfrac{1}{a_2+\cfrac{1}{a_3+{_\ddots}}}} $$where $a_0$ is an integer and $a_1,a_2,a_3,\dots$ are positive integers. Define $k_j(x)$ to be the geometric mean of $a_1,a_2,\dots,a_j$. That is, $k_j(x)=(a_1a_2 \cdots a_j)^{1/j}$. Also define $k_\infty(x)=\lim_{j\to \infty} k_j(x)$. Khinchin proved that almost all irrational numbers $x$ have the same value of $k_\infty(x)\approx2.685452\dots$ known as Khinchin's constant. However, there are some exceptions to this rule. For $n\geq 0$ define $$\rho_n = \sum_{i=0}^{\infty} \frac{2^n}{2^{2^i}} $$For example $\rho_2$, with continued fraction beginning $[3; 3, 1, 3, 4, 3, 1, 3,\dots]$, has $k_\infty(\rho_2)\approx2.059767$. Find the geometric mean of $k_{\infty}(\rho_n)$ for $0\leq n\leq 50$, giving your answer rounded to six digits after the decimal point.
<p> An irrational number $x$ can be uniquely expressed as a <b>continued fraction</b> $[a_0; a_1,a_2,a_3,\dots]$: $$ x=a_{0}+\cfrac{1}{a_1+\cfrac{1}{a_2+\cfrac{1}{a_3+{_\ddots}}}} $$where $a_0$ is an integer and $a_1,a_2,a_3,\dots$ are positive integers. </p> <p> Define $k_j(x)$ to be the <b>geometric mean</b> of $a_1,a_2,\dots,a_j$.<br> That is, $k_j(x)=(a_1a_2 \cdots a_j)^{1/j}$.<br> Also define $k_\infty(x)=\lim_{j\to \infty} k_j(x)$. </p> <p> Khinchin proved that <b>almost all</b> irrational numbers $x$ have the same value of $k_\infty(x)\approx2.685452\dots$ known as <b>Khinchin's constant</b>. However, there are some exceptions to this rule. </p> <p> For $n\geq 0$ define $$\rho_n = \sum_{i=0}^{\infty} \frac{2^n}{2^{2^i}} $$For example $\rho_2$, with continued fraction beginning $[3; 3, 1, 3, 4, 3, 1, 3,\dots]$, has $k_\infty(\rho_2)\approx2.059767$. </p> <p> Find the geometric mean of $k_{\infty}(\rho_n)$ for $0\leq n\leq 50$, giving your answer rounded to six digits after the decimal point. </p>
https://projecteuler.net/problem=911
5679.934966
912
Let $s_n$ be the $n$-th positive integer that does not contain three consecutive ones in its binary representation. For example, $s_1 = 1$ and $s_7 = 8$. Define $F(N)$ to be the sum of $n^2$ for all $n\leq N$ where $s_n$ is odd. You are given $F(10)=199$. Find $F(10^{16})$ giving your answer modulo $10^9+7$.
<p> Let $s_n$ be the $n$-th positive integer that does not contain three consecutive ones in its binary representation.<br> For example, $s_1 = 1$ and $s_7 = 8$. </p> <p> Define $F(N)$ to be the sum of $n^2$ for all $n\leq N$ where $s_n$ is odd. You are given $F(10)=199$. </p> <p> Find $F(10^{16})$ giving your answer modulo $10^9+7$. </p>
https://projecteuler.net/problem=912
674045136
913
The numbers from $1$ to $12$ can be arranged into a $3 \times 4$ matrix in either row-major or column-major order: $$R=\begin{pmatrix} 1 & 2 & 3 & 4\\ 5 & 6 & 7 & 8\\ 9 & 10 & 11 & 12\end{pmatrix}, C=\begin{pmatrix} 1 & 4 & 7 & 10\\ 2 & 5 & 8 & 11\\ 3 & 6 & 9 & 12\end{pmatrix}$$ By swapping two entries at a time, at least $8$ swaps are needed to transform $R$ to $C$. Let $S(n, m)$ be the minimal number of swaps needed to transform an $n\times m$ matrix of $1$ to $nm$ from row-major order to column-major order. Thus $S(3, 4) = 8$. You are given that the sum of $S(n, m)$ for $2 \leq n \leq m \leq 100$ is $12578833$. Find the sum of $S(n^4, m^4)$ for $2 \leq n \leq m \leq 100$.
<p> The numbers from $1$ to $12$ can be arranged into a $3 \times 4$ matrix in either <strong>row-major</strong> or <strong>column-major</strong> order: $$R=\begin{pmatrix} 1 &amp; 2 &amp; 3 &amp; 4\\ 5 &amp; 6 &amp; 7 &amp; 8\\ 9 &amp; 10 &amp; 11 &amp; 12\end{pmatrix}, C=\begin{pmatrix} 1 &amp; 4 &amp; 7 &amp; 10\\ 2 &amp; 5 &amp; 8 &amp; 11\\ 3 &amp; 6 &amp; 9 &amp; 12\end{pmatrix}$$ By swapping two entries at a time, at least $8$ swaps are needed to transform $R$ to $C$.</p> <p> Let $S(n, m)$ be the minimal number of swaps needed to transform an $n\times m$ matrix of $1$ to $nm$ from row-major order to column-major order. Thus $S(3, 4) = 8$.</p> <p> You are given that the sum of $S(n, m)$ for $2 \leq n \leq m \leq 100$ is $12578833$.</p> <p> Find the sum of $S(n^4, m^4)$ for $2 \leq n \leq m \leq 100$.</p>
https://projecteuler.net/problem=913
2101925115560555020
914
For a given integer $R$ consider all primitive Pythagorean triangles that can fit inside, without touching, a circle with radius $R$. Define $F(R)$ to be the largest inradius of those triangles. You are given $F(100) = 36$. Find $F(10^{18})$.
<p> For a given integer $R$ consider all primitive Pythagorean triangles that can fit inside, without touching, a circle with radius $R$. Define $F(R)$ to be the largest inradius of those triangles. You are given $F(100) = 36$.</p> <p> Find $F(10^{18})$.</p>
https://projecteuler.net/problem=914
414213562371805310
915
The function $s(n)$ is defined recursively for positive integers by $s(1) = 1$ and $s(n+1) = \big(s(n) - 1\big)^3 +2$ for $n\geq 1$. The sequence begins: $s(1) = 1, s(2) = 2, s(3) = 3, s(4) = 10, \ldots$. For positive integers $N$, define $$T(N) = \sum_{a=1}^N \sum_{b=1}^N \gcd\Big(s\big(s(a)\big), s\big(s(b)\big)\Big).$$ You are given $T(3) = 12$, $T(4) \equiv 24881925$ and $T(100)\equiv 14416749$ both modulo $123456789$. Find $T(10^8)$. Give your answer modulo $123456789$.
<p> The function $s(n)$ is defined recursively for positive integers by $s(1) = 1$ and $s(n+1) = \big(s(n) - 1\big)^3 +2$ for $n\geq 1$.<br> The sequence begins: $s(1) = 1, s(2) = 2, s(3) = 3, s(4) = 10, \ldots$.</p> <p> For positive integers $N$, define $$T(N) = \sum_{a=1}^N \sum_{b=1}^N \gcd\Big(s\big(s(a)\big), s\big(s(b)\big)\Big).$$ You are given $T(3) = 12$, $T(4) \equiv 24881925$ and $T(100)\equiv 14416749$ both modulo $123456789$.</p> <p> Find $T(10^8)$. Give your answer modulo $123456789$.</p>
https://projecteuler.net/problem=915
55601924
916
Let $P(n)$ be the number of permutations of $\{1,2,3,\ldots,2n\}$ such that: 1. There is no ascending subsequence with more than $n+1$ elements, and 2. There is no descending subsequence with more than two elements. Note that subsequences need not be contiguous. For example, the permutation $(4,1,3,2)$ is not counted because it has a descending subsequence of three elements: $(4,3,2)$. You are given $P(2)=13$ and $P(10) \equiv 45265702 \pmod{10^9 + 7}$. Find $P(10^8)$ and give your answer modulo $10^9 + 7$.
<p>Let $P(n)$ be the number of permutations of $\{1,2,3,\ldots,2n\}$ such that: <br> 1. There is no ascending subsequence with more than $n+1$ elements, and <br> 2. There is no descending subsequence with more than two elements. </p> <p>Note that subsequences need not be contiguous. For example, the permutation $(4,1,3,2)$ is not counted because it has a descending subsequence of three elements: $(4,3,2)$. You are given $P(2)=13$ and $P(10) \equiv 45265702 \pmod{10^9 + 7}$.</p> <p>Find $P(10^8)$ and give your answer modulo $10^9 + 7$.</p>
https://projecteuler.net/problem=916
877789135
917
The sequence $s_n$ is defined by $s_1 = 102022661$ and $s_n = s_{n-1}^2 \bmod {998388889}$ for $n > 1$. Let $a_n = s_{2n - 1}$ and $b_n = s_{2n}$ for $n=1,2,...$ Define an $N \times N$ matrix whose values are $M_{i,j} = a_i + b_j$. Let $A(N)$ be the minimal path sum from $M_{1,1}$ (top left) to $M_{N,N}$ (bottom right), where each step is either right or down. You are given $A(1) = 966774091$, $A(2) = 2388327490$ and $A(10) = 13389278727$. Find $A(10^7)$.
<p>The sequence $s_n$ is defined by $s_1 = 102022661$ and $s_n = s_{n-1}^2 \bmod {998388889}$ for $n &gt; 1$.</p> <p>Let $a_n = s_{2n - 1}$ and $b_n = s_{2n}$ for $n=1,2,...$</p> <p>Define an $N \times N$ matrix whose values are $M_{i,j} = a_i + b_j$.</p> <p>Let $A(N)$ be the minimal path sum from $M_{1,1}$ (top left) to $M_{N,N}$ (bottom right), where each step is either right or down.</p> <p>You are given $A(1) = 966774091$, $A(2) = 2388327490$ and $A(10) = 13389278727$.</p> <p>Find $A(10^7)$.</p>
https://projecteuler.net/problem=917
9986212680734636
918
The sequence $a_n$ is defined by $a_1=1$, and then recursively for $n\geq1$: $$\begin{align*} a_{2n} &=2a_n\\ a_{2n+1} &=a_n-3a_{n+1} \end{align*}$$ The first ten terms are $1, 2, -5, 4, 17, -10, -17, 8, -47, 34$. Define $\displaystyle S(N) = \sum_{n=1}^N a_n$. You are given $S(10) = -13$. Find $S(10^{12})$.
<p> The sequence $a_n$ is defined by $a_1=1$, and then recursively for $n\geq1$: $$\begin{align*} a_{2n} &amp;=2a_n\\ a_{2n+1} &amp;=a_n-3a_{n+1} \end{align*}$$ The first ten terms are $1, 2, -5, 4, 17, -10, -17, 8, -47, 34$.<br> Define $\displaystyle S(N) = \sum_{n=1}^N a_n$. You are given $S(10) = -13$.<br> Find $S(10^{12})$. </p>
https://projecteuler.net/problem=918
-6999033352333308
919
We call a triangle fortunate if it has integral sides and at least one of its vertices has the property that the distance from it to the triangle's orthocentre is exactly half the distance from the same vertex to the triangle's circumcentre. Triangle $ABC$ above is an example of a fortunate triangle with sides $(6,7,8)$. The distance from the vertex $C$ to the circumcentre $O$ is $\approx 4.131182$, while the distance from $C$ to the orthocentre $H$ is half that, at $\approx 2.065591$. Define $S(P)$ to be the sum of $a+b+c$ over all fortunate triangles with sides $a\leq b\leq c$ and perimeter not exceeding $P$. For example $S(10)=24$, arising from three triangles with sides $(1,2,2)$, $(2,3,4)$, and $(2,4,4)$. You are also given $S(100)=3331$. Find $S(10^7)$.
<p>We call a triangle <i>fortunate</i> if it has integral sides and at least one of its vertices has the property that the distance from it to the triangle's <b>orthocentre</b> is exactly half the distance from the same vertex to the triangle's <b>circumcentre</b>.</p> <center><img src="resources/images/0919_remarkablediagram.jpg?1731700434" alt="0919_remarkablediagram.jpg" height="400"></center> <p> Triangle $ABC$ above is an example of a fortunate triangle with sides $(6,7,8)$. The distance from the vertex $C$ to the circumcentre $O$ is $\approx 4.131182$, while the distance from $C$ to the orthocentre $H$ is half that, at $\approx 2.065591$. </p> <p> Define $S(P)$ to be the sum of $a+b+c$ over all fortunate triangles with sides $a\leq b\leq c$ and perimeter not exceeding $P$. </p> <p> For example $S(10)=24$, arising from three triangles with sides $(1,2,2)$, $(2,3,4)$, and $(2,4,4)$. You are also given $S(100)=3331$. </p> <p> Find $S(10^7)$. </p>
https://projecteuler.net/problem=919
134222859969633
920
For a positive integer $n$ we define $\tau(n)$ to be the count of the divisors of $n$. For example, the divisors of $12$ are $\{1,2,3,4,6,12\}$ and so $\tau(12) = 6$. A positive integer $n$ is a tau number if it is divisible by $\tau(n)$. For example $\tau(12)=6$ and $6$ divides $12$ so $12$ is a tau number. Let $m(k)$ be the smallest tau number $x$ such that $\tau(x) = k$. For example, $m(8) = 24$, $m(12)=60$ and $m(16)=384$. Further define $M(n)$ to be the sum of all $m(k)$ whose values do not exceed $10^n$. You are given $M(3) = 3189$. Find $M(16)$.
<p>For a positive integer $n$ we define $\tau(n)$ to be the count of the divisors of $n$. For example, the divisors of $12$ are $\{1,2,3,4,6,12\}$ and so $\tau(12) = 6$.</p> <p> A positive integer $n$ is a <b>tau number</b> if it is divisible by $\tau(n)$. For example $\tau(12)=6$ and $6$ divides $12$ so $12$ is a tau number.</p> <p> Let $m(k)$ be the smallest tau number $x$ such that $\tau(x) = k$. For example, $m(8) = 24$, $m(12)=60$ and $m(16)=384$.</p> <p> Further define $M(n)$ to be the sum of all $m(k)$ whose values do not exceed $10^n$. You are given $M(3) = 3189$.</p> <p> Find $M(16)$.</p>
https://projecteuler.net/problem=920
1154027691000533893
921
Consider the following recurrence relation: $$\begin{align} a_0 &= \frac{\sqrt 5 + 1}2\\ a_{n+1} &= \dfrac{a_n(a_n^4 + 10a_n^2 + 5)}{5a_n^4 + 10a_n^2 + 1} \end{align}$$ Note that $a_0$ is the golden ratio. $a_n$ can always be written in the form $\dfrac{p_n\sqrt{5}+1}{q_n}$, where $p_n$ and $q_n$ are positive integers. Let $s(n)=p_n^5+q_n^5$. So, $s(0)=1^5+2^5=33$. The Fibonacci sequence is defined as: $F_1=1$, $F_2=1$, $F_n=F_{n-1}+F_{n-2}$ for $n > 2$. Define $\displaystyle S(m)=\sum_{i=2}^{m}s(F_i)$. Find $S(1618034)$. Submit your answer modulo $398874989$.
<p>Consider the following recurrence relation: $$\begin{align} a_0 &amp;= \frac{\sqrt 5 + 1}2\\ a_{n+1} &amp;= \dfrac{a_n(a_n^4 + 10a_n^2 + 5)}{5a_n^4 + 10a_n^2 + 1} \end{align}$$</p> <p> Note that $a_0$ is the <b>golden ratio</b>.</p> <p> $a_n$ can always be written in the form $\dfrac{p_n\sqrt{5}+1}{q_n}$, where $p_n$ and $q_n$ are positive integers.</p> <p> Let $s(n)=p_n^5+q_n^5$. So, $s(0)=1^5+2^5=33$.</p> <p> The <b>Fibonacci sequence</b> is defined as: $F_1=1$, $F_2=1$, $F_n=F_{n-1}+F_{n-2}$ for $n &gt; 2$.</p> <p> Define $\displaystyle S(m)=\sum_{i=2}^{m}s(F_i)$.</p> <p> Find $S(1618034)$. Submit your answer modulo $398874989$.</p>
https://projecteuler.net/problem=921
378401935
922
A Young diagram is a finite collection of (equally-sized) squares in a grid-like arrangement of rows and columns, such that - the left-most squares of all rows are aligned vertically; - the top squares of all columns are aligned horizontally; - the rows are non-increasing in size as we move top to bottom; - the columns are non-increasing in size as we move left to right. Two examples of Young diagrams are shown below. Two players Right and Down play a game on several Young diagrams, all disconnected from each other. Initially, a token is placed in the top-left square of each diagram. Then they take alternating turns, starting with Right. On Right's turn, Right selects a token on one diagram and moves it any number of squares to the right. On Down's turn, Down selects a token on one diagram and moves it any number of squares downwards. A player unable to make a legal move on their turn loses the game. For $a,b,k\geq 1$ we define an $(a,b,k)$-staircase to be the Young diagram where the bottom-right frontier consists of $k$ steps of vertical height $a$ and horizontal length $b$. Shown below are four examples of staircases with $(a,b,k)$ respectively $(1,1,4),$ $(5,1,1),$ $(3,3,2),$ $(2,4,3)$. Additionally, define the weight of an $(a,b,k)$-staircase to be $a+b+k$. Let $R(m, w)$ be the number ways of choosing $m$ staircases, each having weight not exceeding $w$, upon which Right (moving first in the game) will win the game assuming optimal play. Different orderings of the same set of staircases are to be counted separately. For example, $R(2, 4)=7$ is illustrated below, with tokens as grey circles drawn in their initial positions. You are also given $R(3, 9)=314104$. Find $R(8, 64)$ giving your answer modulo $10^9+7$.
<p> A <strong>Young diagram</strong> is a finite collection of (equally-sized) squares in a grid-like arrangement of rows and columns, such that</p> <ul> <li>the left-most squares of all rows are aligned vertically; </li><li>the top squares of all columns are aligned horizontally; </li><li>the rows are non-increasing in size as we move top to bottom; </li><li>the columns are non-increasing in size as we move left to right. </li></ul> <p> Two examples of Young diagrams are shown below.</p> <div style="text-align:center;"> <img src="resources/images/0922_youngs_game_diagrams.png?1731534949" alt="0922_youngs_game_diagrams.png"></div> <p> Two players Right and Down play a game on several Young diagrams, all disconnected from each other. Initially, a token is placed in the top-left square of each diagram. Then they take alternating turns, starting with Right. On Right's turn, Right selects a token on one diagram and moves it <b>any number of squares</b> to the right. On Down's turn, Down selects a token on one diagram and moves it <b>any number of squares</b> downwards. A player unable to make a legal move on their turn loses the game.</p> <p> For $a,b,k\geq 1$ we define an <dfn>$(a,b,k)$-staircase</dfn> to be the Young diagram where the bottom-right frontier consists of $k$ <dfn>steps</dfn> of vertical height $a$ and horizontal length $b$. Shown below are four examples of staircases with $(a,b,k)$ respectively $(1,1,4),$ $(5,1,1),$ $(3,3,2),$ $(2,4,3)$.</p> <div style="text-align:center;"> <img src="resources/images/0922_youngs_game_staircases.png?1731535243" alt="0922_youngs_game_staircases.png"></div> <p> Additionally, define the <dfn>weight</dfn> of an $(a,b,k)$-staircase to be $a+b+k$.</p> <p> Let $R(m, w)$ be the number ways of choosing $m$ staircases, each having weight not exceeding $w$, upon which Right (moving first in the game) will win the game assuming optimal play. Different orderings of the same set of staircases are to be counted separately.</p> <p> For example, $R(2, 4)=7$ is illustrated below, with tokens as grey circles drawn in their initial positions.</p> <div style="text-align:center;"> <img src="resources/images/0922_youngs_game_example.png?1731535375" alt="0922_youngs_game_example.png"></div> <p> You are also given $R(3, 9)=314104$.</p> <p> Find $R(8, 64)$ giving your answer modulo $10^9+7$.</p>
https://projecteuler.net/problem=922
858945298
923
A Young diagram is a finite collection of (equally-sized) squares in a grid-like arrangement of rows and columns, such that - the left-most squares of all rows are aligned vertically; - the top squares of all columns are aligned horizontally; - the rows are non-increasing in size as we move top to bottom; - the columns are non-increasing in size as we move left to right. Two examples of Young diagrams are shown below. Two players Right and Down play a game on several Young diagrams, all disconnected from each other. Initially, a token is placed in the top-left square of each diagram. Then they take alternating turns, starting with Right. On Right's turn, Right selects a token on one diagram and moves it one square to the right. On Down's turn, Down selects a token on one diagram and moves it one square downwards. A player unable to make a legal move on their turn loses the game. For $a,b,k\geq 1$ we define an $(a,b,k)$-staircase to be the Young diagram where the bottom-right frontier consists of $k$ steps of vertical height $a$ and horizontal length $b$. Shown below are four examples of staircases with $(a,b,k)$ respectively $(1,1,4),$ $(5,1,1),$ $(3,3,2),$ $(2,4,3)$. Additionally, define the weight of an $(a,b,k)$-staircase to be $a+b+k$. Let $S(m, w)$ be the number ways of choosing $m$ staircases, each having weight not exceeding $w$, upon which Right (moving first in the game) will win the game assuming optimal play. Different orderings of the same set of staircases are to be counted separately. For example, $S(2, 4)=7$ is illustrated below, with tokens as grey circles drawn in their initial positions. You are also given $S(3, 9)=315319$. Find $S(8, 64)$ giving your answer modulo $10^9+7$.
<p> A <strong>Young diagram</strong> is a finite collection of (equally-sized) squares in a grid-like arrangement of rows and columns, such that</p> <ul> <li>the left-most squares of all rows are aligned vertically; </li><li>the top squares of all columns are aligned horizontally; </li><li>the rows are non-increasing in size as we move top to bottom; </li><li>the columns are non-increasing in size as we move left to right. </li></ul> <p> Two examples of Young diagrams are shown below.</p> <div style="text-align:center;"> <img src="resources/images/0922_youngs_game_diagrams.png?1731534949" alt="0922_youngs_game_diagrams.png"></div> <p> Two players Right and Down play a game on several Young diagrams, all disconnected from each other. Initially, a token is placed in the top-left square of each diagram. Then they take alternating turns, starting with Right. On Right's turn, Right selects a token on one diagram and moves it <b>one square</b> to the right. On Down's turn, Down selects a token on one diagram and moves it <b>one square</b> downwards. A player unable to make a legal move on their turn loses the game.</p> <p> For $a,b,k\geq 1$ we define an <dfn>$(a,b,k)$-staircase</dfn> to be the Young diagram where the bottom-right frontier consists of $k$ <dfn>steps</dfn> of vertical height $a$ and horizontal length $b$. Shown below are four examples of staircases with $(a,b,k)$ respectively $(1,1,4),$ $(5,1,1),$ $(3,3,2),$ $(2,4,3)$.</p> <div style="text-align:center;"> <img src="resources/images/0922_youngs_game_staircases.png?1731535243" alt="0922_youngs_game_staircases.png"></div> <p> Additionally, define the <dfn>weight</dfn> of an $(a,b,k)$-staircase to be $a+b+k$.</p> <p> Let $S(m, w)$ be the number ways of choosing $m$ staircases, each having weight not exceeding $w$, upon which Right (moving first in the game) will win the game assuming optimal play. Different orderings of the same set of staircases are to be counted separately.</p> <p> For example, $S(2, 4)=7$ is illustrated below, with tokens as grey circles drawn in their initial positions.</p> <div style="text-align:center;"> <img src="resources/images/0922_youngs_game_example.png?1731535375" alt="0922_youngs_game_example.png"></div> <p> You are also given $S(3, 9)=315319$.</p> <p> Find $S(8, 64)$ giving your answer modulo $10^9+7$.</p>
https://projecteuler.net/problem=923
740759929
924
Let $B(n)$ be the smallest number larger than $n$ that can be formed by rearranging digits of $n$, or $0$ if no such number exists. For example, $B(245) = 254$ and $B(542) = 0$. Define $a_0 = 0$ and $a_n = a_{n - 1}^2 + 2$ for $n>0$. Let $\displaystyle U(N) = \sum_{n = 1}^N B(a_n)$. You are given $U(10) \equiv 543870437 \pmod{10^9+7}$. Find $U(10^{16})$. Give your answer modulo $10^9 + 7$.
<p>Let $B(n)$ be the smallest number larger than $n$ that can be formed by rearranging digits of $n$, or $0$ if no such number exists. For example, $B(245) = 254$ and $B(542) = 0$.</p> <p>Define $a_0 = 0$ and $a_n = a_{n - 1}^2 + 2$ for $n&gt;0$. Let $\displaystyle U(N) = \sum_{n = 1}^N B(a_n)$. You are given $U(10) \equiv 543870437 \pmod{10^9+7}$.</p> <p>Find $U(10^{16})$. Give your answer modulo $10^9 + 7$.</p>
https://projecteuler.net/problem=924
811141860
925
Let $B(n)$ be the smallest number larger than $n$ that can be formed by rearranging digits of $n$, or $0$ if no such number exists. For example, $B(245) = 254$ and $B(542) = 0$. Define $\displaystyle T(N) = \sum_{n=1}^N B(n^2)$. You are given $T(10)=270$ and $T(100)=335316$. Find $T(10^{16})$. Give your answer modulo $10^9 + 7$.
<p>Let $B(n)$ be the smallest number larger than $n$ that can be formed by rearranging digits of $n$, or $0$ if no such number exists. For example, $B(245) = 254$ and $B(542) = 0$.</p> <p>Define $\displaystyle T(N) = \sum_{n=1}^N B(n^2)$. You are given $T(10)=270$ and $T(100)=335316$.</p> <p>Find $T(10^{16})$. Give your answer modulo $10^9 + 7$.</p>
https://projecteuler.net/problem=925
400034379
926
A round number is a number that ends with one or more zeros in a given base. Let us define the roundness of a number $n$ in base $b$ as the number of zeros at the end of the base $b$ representation of $n$. For example, $20$ has roundness $2$ in base $2$, because the base $2$ representation of $20$ is $10100$, which ends with $2$ zeros. Also define $R(n)$, the total roundness of a number $n$, as the sum of the roundness of $n$ in base $b$ for all $b > 1$. For example, $20$ has roundness $2$ in base $2$ and roundness $1$ in base $4$, $5$, $10$, $20$, hence we get $R(20)=6$. You are also given $R(10!) = 312$. Find $R(10\,000\,000!)$. Give your answer modulo $10^9 + 7$.
<p> A <strong>round number</strong> is a number that ends with one or more zeros in a given base.</p> <p> Let us define the <dfn>roundness</dfn> of a number $n$ in base $b$ as the number of zeros at the end of the base $b$ representation of $n$.<br> For example, $20$ has roundness $2$ in base $2$, because the base $2$ representation of $20$ is $10100$, which ends with $2$ zeros.</p> <p> Also define $R(n)$, the <dfn>total roundness</dfn> of a number $n$, as the sum of the roundness of $n$ in base $b$ for all $b &gt; 1$.<br> For example, $20$ has roundness $2$ in base $2$ and roundness $1$ in base $4$, $5$, $10$, $20$, hence we get $R(20)=6$.<br> You are also given $R(10!) = 312$.</p> <p> Find $R(10\,000\,000!)$. Give your answer modulo $10^9 + 7$.</p>
https://projecteuler.net/problem=926
40410219
927
A full $k$-ary tree is a tree with a single root node, such that every node is either a leaf or has exactly $k$ ordered children. The height of a $k$-ary tree is the number of edges in the longest path from the root to a leaf. For instance, there is one full 3-ary tree of height 0, one full 3-ary tree of height 1, and seven full 3-ary trees of height 2. These seven are shown below. For integers $n$ and $k$ with $n\ge 0$ and $k \ge 2$, define $t_k(n)$ to be the number of full $k$-ary trees of height $n$ or less. Thus, $t_3(0) = 1$, $t_3(1) = 2$, and $t_3(2) = 9$. Also, $t_2(0) = 1$, $t_2(1) = 2$, and $t_2(2) = 5$. Define $S_k$ to be the set of positive integers $m$ such that $m$ divides $t_k(n)$ for some integer $n\ge 0$. For instance, the above values show that 1, 2, and 5 are in $S_2$ and 1, 2, 3, and 9 are in $S_3$. Let $S = \bigcap_p S_p$ where the intersection is taken over all primes $p$. Finally, define $R(N)$ to be the sum of all elements of $S$ not exceeding $N$. You are given that $R(20) = 18$ and $R(1000) = 2089$. Find $R(10^7)$.
<p>A full $k$-ary tree is a tree with a single root node, such that every node is either a leaf or has exactly $k$ ordered children. The <b>height</b> of a $k$-ary tree is the number of edges in the longest path from the root to a leaf.</p> <p> For instance, there is one full 3-ary tree of height 0, one full 3-ary tree of height 1, and seven full 3-ary trees of height 2. These seven are shown below.</p> <img src="resources/images/0927_PrimeTrees.jpg?1735590785" alt="0927_PrimeTrees.jpg"> <p> For integers $n$ and $k$ with $n\ge 0$ and $k \ge 2$, define $t_k(n)$ to be the number of full $k$-ary trees of height $n$ or less.<br> Thus, $t_3(0) = 1$, $t_3(1) = 2$, and $t_3(2) = 9$. Also, $t_2(0) = 1$, $t_2(1) = 2$, and $t_2(2) = 5$.</p> <p> Define $S_k$ to be the set of positive integers $m$ such that $m$ divides $t_k(n)$ for some integer $n\ge 0$. For instance, the above values show that 1, 2, and 5 are in $S_2$ and 1, 2, 3, and 9 are in $S_3$.</p> <p> Let $S = \bigcap_p S_p$ where the intersection is taken over all primes $p$. Finally, define $R(N)$ to be the sum of all elements of $S$ not exceeding $N$. You are given that $R(20) = 18$ and $R(1000) = 2089$.</p> <p> Find $R(10^7)$.</p>
https://projecteuler.net/problem=927
207282955
928
This problem is based on (but not identical to) the scoring for the card game Cribbage. Consider a normal pack of $52$ cards. A Hand is a selection of one or more of these cards. For each Hand the Hand score is the sum of the values of the cards in the Hand where the value of Aces is $1$ and the value of court cards (Jack, Queen, King) is $10$. The Cribbage score is obtained for a Hand by adding together the scores for: - Pairs. A pair is two cards of the same rank. Every pair is worth $2$ points. - Runs. A run is a set of at least $3$ cards whose ranks are consecutive, e.g. 9, 10, Jack. Note that Ace is never high, so Queen, King, Ace is not a valid run. The number of points for each run is the size of the run. All locally maximum runs are counted. For example, 2, 3, 4, 5, 7, 8, 9 the two runs of 2, 3, 4, 5 and 7, 8, 9 are counted but not 2, 3, 4 or 3, 4, 5. - Fifteens. A fifteen is a combination of cards that has value adding to $15$. Every fifteen is worth $2$ points. For this purpose the value of the cards is the same as in the Hand Score. For example, $(5 \spadesuit, 5 \clubsuit, 5 \diamondsuit, K \heartsuit)$ has a Cribbage score of $14$ as there are four ways that fifteen can be made and also three pairs can be made. The example $( A \diamondsuit, A \heartsuit, 2 \clubsuit, 3 \heartsuit, 4 \clubsuit, 5 \spadesuit)$ has a Cribbage score of $16$: two runs of five worth $10$ points, two ways of getting fifteen worth $4$ points and one pair worth $2$ points. In this example the Hand score is equal to the Cribbage score. Find the number of Hands in a normal pack of cards where the Hand score is equal to the Cribbage score.
<p>This problem is based on (but not identical to) the scoring for the card game <a href="https://en.wikipedia.org/wiki/Cribbage">Cribbage</a>.</p> <p> Consider a normal pack of $52$ cards. A Hand is a selection of one or more of these cards.</p> <p> For each Hand the <i>Hand score</i> is the sum of the values of the cards in the Hand where the value of Aces is $1$ and the value of court cards (Jack, Queen, King) is $10$.</p> <p> The <i>Cribbage score</i> is obtained for a Hand by adding together the scores for:</p> <ul> <li> Pairs. A pair is two cards of the same rank. Every pair is worth $2$ points.</li> <li> Runs. A run is a set of at least $3$ cards whose ranks are consecutive, e.g. 9, 10, Jack. Note that Ace is never high, so Queen, King, Ace is <b>not</b> a valid run. The number of points for each run is the size of the run. All locally maximum runs are counted. For example, 2, 3, 4, 5, 7, 8, 9 the two runs of 2, 3, 4, 5 and 7, 8, 9 are counted but not 2, 3, 4 or 3, 4, 5.</li> <li> Fifteens. A fifteen is a combination of cards that has value adding to $15$. Every fifteen is worth $2$ points. For this purpose the value of the cards is the same as in the Hand Score.</li></ul> <p> For example, $(5 \spadesuit, 5 \clubsuit, 5 \diamondsuit, K \heartsuit)$ has a Cribbage score of $14$ as there are four ways that fifteen can be made and also three pairs can be made.</p> <p> The example $( A \diamondsuit, A \heartsuit, 2 \clubsuit, 3 \heartsuit, 4 \clubsuit, 5 \spadesuit)$ has a Cribbage score of $16$: two runs of five worth $10$ points, two ways of getting fifteen worth $4$ points and one pair worth $2$ points. In this example the Hand score is equal to the Cribbage score.</p> <p> Find the number of Hands in a normal pack of cards where the Hand score is equal to the Cribbage score.</p>
https://projecteuler.net/problem=928
81108001093
929
A composition of $n$ is a sequence of positive integers which sum to $n$. Such a sequence can be split into runs, where a run is a maximal contiguous subsequence of equal terms. For example, $2,2,1,1,1,3,2,2$ is a composition of $14$ consisting of four runs: $2, 2\quad 1, 1, 1\quad 3 \quad 2, 2$ Let $F(n)$ be the number of compositions of $n$ where every run has odd length. For example, $F(5)=10$: $$\begin{align*} & 5 &&4,1 && 3,2 &&2,3 &&2,1,2\\ &2,1,1,1 &&1,4 &&1,3,1 &&1,1,1,2 &&1,1,1,1,1 \end{align*}$$ Find $F(10^5)$. Give your answer modulo $1111124111$.
<p>A <b>composition</b> of $n$ is a sequence of positive integers which sum to $n$. Such a sequence can be split into <i>runs</i>, where a run is a maximal contiguous subsequence of equal terms.</p> <p>For example, $2,2,1,1,1,3,2,2$ is a composition of $14$ consisting of four runs:</p> <center>$2, 2\quad 1, 1, 1\quad 3 \quad 2, 2$</center> <p>Let $F(n)$ be the number of compositions of $n$ where every run has odd length.</p> <p>For example, $F(5)=10$:</p> $$\begin{align*} &amp; 5 &amp;&amp;4,1 &amp;&amp; 3,2 &amp;&amp;2,3 &amp;&amp;2,1,2\\ &amp;2,1,1,1 &amp;&amp;1,4 &amp;&amp;1,3,1 &amp;&amp;1,1,1,2 &amp;&amp;1,1,1,1,1 \end{align*}$$ <p>Find $F(10^5)$. Give your answer modulo $1111124111$.</p>
https://projecteuler.net/problem=929
57322484
930
Given $n\ge 2$ bowls arranged in a circle, $m\ge 2$ balls are distributed amongst them. Initially the balls are distributed randomly: for each ball, a bowl is chosen equiprobably and independently of the other balls. After this is done, we start the following process: - Choose one of the $m$ balls equiprobably at random. - Choose a direction to move - either clockwise or anticlockwise - again equiprobably at random. - Move the chosen ball to the neighbouring bowl in the chosen direction. - Return to step 1. This process stops when all the $m$ balls are located in the same bowl. Note that this may be after zero steps, if the balls happen to have been initially distributed all in the same bowl. Let $F(n, m)$ be the expected number of times we move a ball before the process stops. For example, $F(2, 2) = \frac{1}{2}$, $F(3, 2) = \frac{4}{3}$, $F(2, 3) = \frac{9}{4}$, and $F(4, 5) = \frac{6875}{24}$. Let $G(N, M) = \sum_{n=2}^N \sum_{m=2}^M F(n, m)$. For example, $G(3, 3) = \frac{137}{12}$ and $G(4, 5) = \frac{6277}{12}$. You are also given that $G(6, 6) \approx 1.681521567954e4$ in scientific format with 12 significant digits after the decimal point. Find $G(12, 12)$. Give your answer in scientific format with 12 significant digits after the decimal point.
<p>Given $n\ge 2$ bowls arranged in a circle, $m\ge 2$ balls are distributed amongst them.</p> <p>Initially the balls are distributed randomly: for each ball, a bowl is chosen equiprobably and independently of the other balls. After this is done, we start the following process:</p> <ol> <li>Choose one of the $m$ balls equiprobably at random.</li> <li>Choose a direction to move - either clockwise or anticlockwise - again equiprobably at random.</li> <li>Move the chosen ball to the neighbouring bowl in the chosen direction.</li> <li>Return to step 1.</li> </ol> <p>This process stops when all the $m$ balls are located in the same bowl. Note that this may be after zero steps, if the balls happen to have been initially distributed all in the same bowl.</p> <p>Let $F(n, m)$ be the expected number of times we move a ball before the process stops. For example, $F(2, 2) = \frac{1}{2}$, $F(3, 2) = \frac{4}{3}$, $F(2, 3) = \frac{9}{4}$, and $F(4, 5) = \frac{6875}{24}$.</p> <p>Let $G(N, M) = \sum_{n=2}^N \sum_{m=2}^M F(n, m)$. For example, $G(3, 3) = \frac{137}{12}$ and $G(4, 5) = \frac{6277}{12}$. You are also given that $G(6, 6) \approx 1.681521567954e4$ in scientific format with 12 significant digits after the decimal point.</p> <p>Find $G(12, 12)$. Give your answer in scientific format with 12 significant digits after the decimal point.</p>
https://projecteuler.net/problem=930
1.345679959251e12
931
For a positive integer $n$ construct a graph using all the divisors of $n$ as the vertices. An edge is drawn between $a$ and $b$ if $a$ is divisible by $b$ and $a/b$ is prime, and is given weight $\phi(a)-\phi(b)$, where $\phi$ is the Euler totient function. Define $t(n)$ to be the total weight of this graph. The example below shows that $t(45) = 52$ Let $T(N)=\displaystyle\sum_{n=1}^{N} t(n)$. You are given $T(10)=26$ and $T(10^2)=5282$. Find $T(10^{12})$. Give your answer modulo $715827883$.
<p> For a positive integer $n$ construct a graph using all the divisors of $n$ as the vertices. An edge is drawn between $a$ and $b$ if $a$ is divisible by $b$ and $a/b$ is prime, and is given weight $\phi(a)-\phi(b)$, where $\phi$ is the Euler totient function.<br> Define $t(n)$ to be the total weight of this graph.<br> The example below shows that $t(45) = 52$ </p> <img src="resources/images/0931_totientgraph.png?1738586879" alt="0931_totientgraph.png"> <p> Let $T(N)=\displaystyle\sum_{n=1}^{N} t(n)$. You are given $T(10)=26$ and $T(10^2)=5282$. </p> <p> Find $T(10^{12})$. Give your answer modulo $715827883$. </p>
https://projecteuler.net/problem=931
128856311
932
For the year $2025$ $$2025 = (20 + 25)^2$$ Given positive integers $a$ and $b$, the concatenation $ab$ we call a $2025$-number if $ab = (a+b)^2$. Other examples are $3025$ and $81$. Note $9801$ is not a $2025$-number because the concatenation of $98$ and $1$ is $981$. Let $T(n)$ be the sum of all $2025$-numbers with $n$ digits or less. You are given $T(4) = 5131$. Find $T(16)$.
<p>For the year $2025$</p> $$2025 = (20 + 25)^2$$ <p>Given positive integers $a$ and $b$, the concatenation $ab$ we call a $2025$-number if $ab = (a+b)^2$.<br> Other examples are $3025$ and $81$.<br> Note $9801$ is not a $2025$-number because the concatenation of $98$ and $1$ is $981$.</p> <p> Let $T(n)$ be the sum of all $2025$-numbers with $n$ digits or less. You are given $T(4) = 5131$.</p> <p> Find $T(16)$.</p>
https://projecteuler.net/problem=932
72673459417881349
933
Starting with one piece of integer-sized rectangle paper, two players make moves in turn. A valid move consists of choosing one piece of paper and cutting it both horizontally and vertically, so that it becomes four pieces of smaller rectangle papers, all of which are integer-sized. The player that does not have a valid move loses the game. Let $C(w, h)$ be the number of winning moves for the first player, when the original paper has size $w \times h$. For example, $C(5,3)=4$, with the four winning moves shown below. Also write $\displaystyle D(W, H) = \sum_{w = 2}^W\sum_{h = 2}^H C(w, h)$. You are given that $D(12, 123) = 327398$. Find $D(123, 1234567)$.
<p> Starting with one piece of integer-sized rectangle paper, two players make moves in turn.<br> A valid move consists of choosing one piece of paper and cutting it <b>both</b> horizontally and vertically, so that it becomes four pieces of smaller rectangle papers, all of which are integer-sized.<br> The player that does not have a valid move loses the game.</p> <p> Let $C(w, h)$ be the number of winning moves for the first player, when the original paper has size $w \times h$. For example, $C(5,3)=4$, with the four winning moves shown below.</p> <center><img src="resources/images/0933_PaperCutting3.jpg?1738704656" alt="0933_PaperCutting2.jpg"></center> <p> Also write $\displaystyle D(W, H) = \sum_{w = 2}^W\sum_{h = 2}^H C(w, h)$. You are given that $D(12, 123) = 327398$.</p> <p> Find $D(123, 1234567)$.</p>
https://projecteuler.net/problem=933
5707485980743099
934
We define the unlucky prime of a number $n$, denoted $u(n)$, as the smallest prime number $p$ such that the remainder of $n$ divided by $p$ (i.e. $n \bmod p$) is not a multiple of seven. For example, $u(14) = 3$, $u(147) = 2$ and $u(1470) = 13$. Let $U(N)$ be the sum $\sum_{n = 1}^N u(n)$. You are given $U(1470) = 4293$. Find $U(10^{17})$.
<p>We define the <i>unlucky prime</i> of a number $n$, denoted $u(n)$, as the smallest prime number $p$ such that the remainder of $n$ divided by $p$ (i.e. $n \bmod p$) is not a multiple of seven.<br> For example, $u(14) = 3$, $u(147) = 2$ and $u(1470) = 13$.</p> <p>Let $U(N)$ be the sum $\sum_{n = 1}^N u(n)$.<br> You are given $U(1470) = 4293$.</p> <p>Find $U(10^{17})$.</p>
https://projecteuler.net/problem=934
292137809490441370
935
A square of side length $b<1$ is rolling around the inside of a larger square of side length $1$, always touching the larger square but without sliding. Initially the two squares share a common corner. At each step, the small square rotates clockwise about a corner that touches the large square, until another of its corners touches the large square. Here is an illustration of the first three steps for $b = \frac5{13}$. For some values of $b$, the small square may return to its initial position after several steps. For example, when $b = \frac12$, this happens in $4$ steps; and for $b = \frac5{13}$ it happens in $24$ steps. Let $F(N)$ be the number of different values of $b$ for which the small square first returns to its initial position within at most $N$ steps. For example, $F(6) = 4$, with the corresponding $b$ values: $$\frac12,\quad 2 - \sqrt 2,\quad 2 + \sqrt 2 - \sqrt{2 + 4\sqrt2},\quad 8 - 5\sqrt2 + 4\sqrt3 - 3\sqrt6,$$ the first three in $4$ steps and the last one in $6$ steps. Note that it does not matter whether the small square returns to its original orientation. Also $F(100) = 805$. Find $F(10^8)$.
<p> A square of side length $b&lt;1$ is rolling around the inside of a larger square of side length $1$, always touching the larger square but without sliding.<br> Initially the two squares share a common corner. At each step, the small square rotates clockwise about a corner that touches the large square, until another of its corners touches the large square. Here is an illustration of the first three steps for $b = \frac5{13}$.</p> <center><img src="resources/images/0935_rolling.png?1738619705" alt="0935_rolling.png"></center> <p> For some values of $b$, the small square may return to its initial position after several steps. For example, when $b = \frac12$, this happens in $4$ steps; and for $b = \frac5{13}$ it happens in $24$ steps.</p> <p> Let $F(N)$ be the number of different values of $b$ for which the small square first returns to its initial position within at most $N$ steps. For example, $F(6) = 4$, with the corresponding $b$ values: $$\frac12,\quad 2 - \sqrt 2,\quad 2 + \sqrt 2 - \sqrt{2 + 4\sqrt2},\quad 8 - 5\sqrt2 + 4\sqrt3 - 3\sqrt6,$$ the first three in $4$ steps and the last one in $6$ steps. Note that it does not matter whether the small square returns to its original <b>orientation</b>.<br> Also $F(100) = 805$.</p> <p> Find $F(10^8)$.</p>
https://projecteuler.net/problem=935
759908921637225
936
A peerless tree is a tree with no edge between two vertices of the same degree. Let $P(n)$ be the number of peerless trees on $n$ unlabelled vertices. There are six of these trees on seven unlabelled vertices, $P(7)=6$, shown below. Define $\displaystyle S(N) = \sum_{n=3}^N P(n)$. You are given $S(10) = 74$. Find $S(50)$.
<p>A <i>peerless tree</i> is a tree with no edge between two vertices of the same degree. Let $P(n)$ be the number of peerless trees on $n$ unlabelled vertices.</p> <p>There are six of these trees on seven unlabelled vertices, $P(7)=6$, shown below.</p> <img src="resources/images/0936_diagram.jpg?1738919825" alt="0936_diagram.jpg"> <p>Define $\displaystyle S(N) = \sum_{n=3}^N P(n)$. You are given $S(10) = 74$.</p> <p>Find $S(50)$.</p>
https://projecteuler.net/problem=936
12144907797522336
937
Let $\theta=\sqrt{-2}$. Define $T$ to be the set of numbers of the form $a+b\theta$, where $a$ and $b$ are integers and either $a\gt 0$, or $a=0$ and $b\gt 0$. For a set $S \subseteq T$ and element $z \in T$, define $p(S,z)$ to be the number of ways of choosing two distinct elements from $S$ with product either $z$ or $-z$. For example if $S=\{1,2,4\}$ and $z=4$, there is only one valid pair of elements with product $\pm4$, namely $1$ and $4$. Thus, in this case $p(S,z)=1$. For another example, if $S=\{1,\theta,1+\theta,2-\theta\}$ and $z=2-\theta$, we have $1\cdot(2-\theta)=z$ and $\theta\cdot(1+\theta)=-z$, giving $p(S,z)=2$. Let $A$ and $B$ be two sets satisfying the following conditions: - $1 \in A$ - $A \cap B = \emptyset$ - $A \cup B = T$ - $p(A,z) = p(B,z)$ for all $z\in T$ Remarkably, these four conditions uniquely determine the sets $A$ and $B$. Let $F_n$ be the set of the first $n$ factorials: $F_n=\{1!,2!,\dots,n!\}$, and define $G(n)$ to be the sum of all elements of $F_n\cap A$. You are given $G(4) = 25$, $G(7) = 745$, and $G(100) \equiv 709772949 \pmod{10^9+7}$. Find $G(10^8)$ and give your answer modulo $10^9+7$.
<p>Let $\theta=\sqrt{-2}$.</p> <p>Define $T$ to be the set of numbers of the form $a+b\theta$, where $a$ and $b$ are integers and either $a\gt 0$, or $a=0$ and $b\gt 0$. For a set $S \subseteq T$ and element $z \in T$, define $p(S,z)$ to be the number of ways of choosing two distinct elements from $S$ with product either $z$ or $-z$.</p> <p>For example if $S=\{1,2,4\}$ and $z=4$, there is only one valid pair of elements with product $\pm4$, namely $1$ and $4$. Thus, in this case $p(S,z)=1$.</p> <p>For another example, if $S=\{1,\theta,1+\theta,2-\theta\}$ and $z=2-\theta$, we have $1\cdot(2-\theta)=z$ and $\theta\cdot(1+\theta)=-z$, giving $p(S,z)=2$.</p> <p>Let $A$ and $B$ be two sets satisfying the following conditions:</p> <ul> <li>$1 \in A$</li> <li>$A \cap B = \emptyset$</li> <li>$A \cup B = T$</li> <li>$p(A,z) = p(B,z)$ for all $z\in T$</li> </ul> <p>Remarkably, these four conditions uniquely determine the sets $A$ and $B$.</p> <p>Let $F_n$ be the set of the first $n$ factorials: $F_n=\{1!,2!,\dots,n!\}$, and define $G(n)$ to be the sum of all elements of $F_n\cap A$.</p> <p>You are given $G(4) = 25$, $G(7) = 745$, and $G(100) \equiv 709772949 \pmod{10^9+7}$.</p> <p>Find $G(10^8)$ and give your answer modulo $10^9+7$.</p>
https://projecteuler.net/problem=937
792169346
938
A deck of cards contains $R$ red cards and $B$ black cards. A card is chosen uniformly randomly from the deck and removed. A second card is then chosen uniformly randomly from the cards remaining and removed. - If both cards are red, they are discarded. - If both cards are black, they are both put back in the deck. - If they are different colours, the red card is put back in the deck and the black card is discarded. Play ends when all the remaining cards in the deck are the same colour and let $P(R,B)$ be the probability that this colour is black. You are given $P(2,2) = 0.4666666667$, $P(10,9) = 0.4118903397$ and $P(34,25) = 0.3665688069$. Find $P(24690,12345)$. Give your answer with 10 digits after the decimal point.
<p> A deck of cards contains $R$ red cards and $B$ black cards.<br> A card is chosen uniformly randomly from the deck and removed. A second card is then chosen uniformly randomly from the cards remaining and removed.</p> <ul> <li> If both cards are red, they are discarded.</li> <li> If both cards are black, they are both put back in the deck.</li> <li> If they are different colours, the red card is put back in the deck and the black card is discarded.</li></ul> <p> Play ends when all the remaining cards in the deck are the same colour and let $P(R,B)$ be the probability that this colour is black. </p> <p> You are given $P(2,2) = 0.4666666667$, $P(10,9) = 0.4118903397$ and $P(34,25) = 0.3665688069$.</p> <p> Find $P(24690,12345)$. Give your answer with 10 digits after the decimal point.</p>
https://projecteuler.net/problem=938
0.2928967987
939
Two players A and B are playing a variant of Nim. At the beginning, there are several piles of stones. Each pile is either at the side of A or at the side of B. The piles are unordered. They make moves in turn. At a player's turn, the player can - either choose a pile on the opponent's side and remove one stone from that pile; - or choose a pile on their own side and remove the whole pile. The winner is the player who removes the last stone. Let $E(N)$ be the number of initial settings with at most $N$ stones such that, whoever plays first, A always has a winning strategy. For example $E(4) = 9$; the settings are: | Nr. | Piles at the side of A | Piles at the side of B | | --- | --- | --- | | 1 | $4$ | none | | 2 | $1, 3$ | none | | 3 | $2, 2$ | none | | 4 | $1, 1, 2$ | none | | 5 | $3$ | $1$ | | 6 | $1, 2$ | $1$ | | 7 | $2$ | $1, 1$ | | 8 | $3$ | none | | 9 | $2$ | none | Find $E(5000) \bmod 1234567891$.
<p> Two players A and B are playing a variant of Nim.<br> At the beginning, there are several piles of stones. Each pile is either at the side of A or at the side of B. The piles are unordered.</p> <p> They make moves in turn. At a player's turn, the player can</p> <ul> <li>either choose a pile on the opponent's side and remove one stone from that pile;</li> <li>or choose a pile on their own side and remove the whole pile.</li></ul> <p>The winner is the player who removes the last stone.</p> <p> Let $E(N)$ be the number of initial settings with at most $N$ stones such that, whoever plays first, A always has a winning strategy.</p> <p> For example $E(4) = 9$; the settings are: </p> <div class="center"><table class="grid center"><tr><th>Nr.</th> <th>Piles at the side of A</th> <th>Piles at the side of B</th> </tr><tr><td>1</td> <td>$4$</td> <td>none</td> </tr><tr><td>2</td> <td>$1, 3$</td> <td>none</td> </tr><tr><td>3</td> <td>$2, 2$</td> <td>none</td> </tr><tr><td>4</td> <td>$1, 1, 2$</td> <td>none</td> </tr><tr><td>5</td> <td>$3$</td> <td>$1$</td> </tr><tr><td>6</td> <td>$1, 2$</td> <td>$1$</td> </tr><tr><td>7</td> <td>$2$</td> <td>$1, 1$</td> </tr><tr><td>8</td> <td>$3$</td> <td>none</td> </tr><tr><td>9</td> <td>$2$</td> <td>none</td> </tr></table></div> <p> Find $E(5000) \bmod 1234567891$.</p>
https://projecteuler.net/problem=939
246776732
940
The Fibonacci sequence $(f_i)$ is the unique sequence such that - $f_0=0$ - $f_1=1$ - $f_{i+1}=f_i+f_{i-1}$ Similarly, there is a unique function $A(m,n)$ such that - $A(0,0)=0$ - $A(0,1)=1$ - $A(m+1,n)=A(m,n+1)+A(m,n)$ - $A(m+1,n+1)=2A(m+1,n)+A(m,n)$ Define $S(k)=\displaystyle\sum_{i=2}^k\sum_{j=2}^k A(f_i,f_j)$. For example $$ \begin{align} S(3)&=A(1,1)+A(1,2)+A(2,1)+A(2,2)\\ &=2+5+7+16\\ &=30 \end{align} $$You are also given $S(5)=10396$. Find $S(50)$, giving your answer modulo $1123581313$.
<p> The <b>Fibonacci sequence</b> $(f_i)$ is the unique sequence such that </p> <ul> <li>$f_0=0$</li> <li>$f_1=1$</li> <li>$f_{i+1}=f_i+f_{i-1}$</li> </ul> <p> Similarly, there is a unique function $A(m,n)$ such that </p> <ul> <li>$A(0,0)=0$</li> <li>$A(0,1)=1$</li> <li>$A(m+1,n)=A(m,n+1)+A(m,n)$</li> <li>$A(m+1,n+1)=2A(m+1,n)+A(m,n)$</li> </ul> <p> Define $S(k)=\displaystyle\sum_{i=2}^k\sum_{j=2}^k A(f_i,f_j)$. For example $$ \begin{align} S(3)&amp;=A(1,1)+A(1,2)+A(2,1)+A(2,2)\\ &amp;=2+5+7+16\\ &amp;=30 \end{align} $$You are also given $S(5)=10396$. </p> <p> Find $S(50)$, giving your answer modulo $1123581313$. </p>
https://projecteuler.net/problem=940
969134784
941
de Bruijn has a digital combination lock with $k$ buttons numbered $0$ to $k-1$ where $k \le 10$. The lock opens when the last $n$ buttons pressed match the preset combination. Unfortunately he has forgotten the combination. He creates a sequence of these digits which contains every possible combination of length $n$. Then by pressing the buttons in this order he is sure to open the lock. Consider all sequences of shortest possible length that contains every possible combination of the digits. Denote by $C(k, n)$ the lexicographically smallest of these. For example, $C(3, 2) = $ 0010211220. Define the sequence $a_n$ by $a_0=0$ and $$a_n=(920461 a_{n-1}+800217387569)\bmod 10^{12} \text{ for }\ n > 0$$ Interpret each $a_n$ as a $12$-digit combination, adding leading zeros for any $a_n$ with less than $12$ digits. Given a positive integer $N$, we are interested in the order the combinations $a_1,\dots,a_N$ appear in $C(10,12)$. Denote by $p_n$ the place, numbered $1,\dots,N$, in which $a_n$ appears out of $a_1,\dots,a_N$. Define $\displaystyle F(N)=\sum_{n=1}^Np_na_n$. For example, the combination $a_1=800217387569$ is entered before $a_2=696996536878$. Therefore: $$F(2)=1\cdot800217387569 + 2\cdot696996536878 = 2194210461325$$ You are also given $F(10)=32698850376317$. Find $F(10^7)$. Give your answer modulo $1234567891$.
<p> de Bruijn has a digital combination lock with $k$ buttons numbered $0$ to $k-1$ where $k \le 10$.<br> The lock opens when the last $n$ buttons pressed match the preset combination.</p> <p> Unfortunately he has forgotten the combination. He creates a sequence of these digits which contains every possible combination of length $n$. Then by pressing the buttons in this order he is sure to open the lock.</p> <p> Consider all sequences of shortest possible length that contains every possible combination of the digits.<br> Denote by $C(k, n)$ the lexicographically smallest of these.</p> <p> For example, $C(3, 2) = $ 0010211220.</p> <p> Define the sequence $a_n$ by $a_0=0$ and<br> $$a_n=(920461 a_{n-1}+800217387569)\bmod 10^{12} \text{ for }\ n &gt; 0$$ Interpret each $a_n$ as a $12$-digit combination, adding leading zeros for any $a_n$ with less than $12$ digits.</p> <p> Given a positive integer $N$, we are interested in the order the combinations $a_1,\dots,a_N$ appear in $C(10,12)$.<br> Denote by $p_n$ the <i>place</i>, numbered $1,\dots,N$, in which $a_n$ appears out of $a_1,\dots,a_N$. Define $\displaystyle F(N)=\sum_{n=1}^Np_na_n$.</p> <p> For example, the combination $a_1=800217387569$ is entered before $a_2=696996536878$. Therefore: $$F(2)=1\cdot800217387569 + 2\cdot696996536878 = 2194210461325$$ You are also given $F(10)=32698850376317$.</p> <p> Find $F(10^7)$. Give your answer modulo $1234567891$.</p>
https://projecteuler.net/problem=941
1068765750
942
Given a natural number $q$, let $p = 2^q - 1$ be the $q$-th Mersenne number. Let $R(q)$ be the minimal square root of $q$ modulo $p$, if one exists. In other words, $R(q)$ is the smallest positive integer $x$ such that $x^2 - q$ is divisible by $p$. For example, $R(5)=6$ and $R(17)=47569$. Find $R(74\,207\,281)$. Give your answer modulo $10^9 + 7$. Note: $2^{74207281}-1$ is prime.
<p>Given a natural number $q$, let $p = 2^q - 1$ be the $q$-th <b>Mersenne number</b>.</p> <p>Let $R(q)$ be the minimal square root of $q$ modulo $p$, if one exists. In other words, $R(q)$ is the smallest positive integer $x$ such that $x^2 - q$ is divisible by $p$.</p> <p>For example, $R(5)=6$ and $R(17)=47569$.</p> <p>Find $R(74\,207\,281)$. Give your answer modulo $10^9 + 7$.</p> <p>Note: $2^{74207281}-1$ is prime.</p>
https://projecteuler.net/problem=942
557539756
943
Given two unequal positive integers $a$ and $b$, we define a self-describing sequence consisting of alternating runs of $a$s and $b$s. The first element is $a$ and the sequence of run lengths is the original sequence. For $a=2, b=3$, the sequence is: $$2, 2, 3, 3, 2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2, 2, 3, 3, 3, 2, 2, 2, 3, 3, 3,...$$ The sequence begins with two $2$s and two $3$s, then three $2$s and three $3$s, so the run lengths $2, 2, 3, 3, ...$ are given by the original sequence. Let $T(a, b, N)$ be the sum of the first $N$ elements of the sequence. You are given $T(2,3,10) = 25$, $T(4,2,10^4) = 30004$, $T(5,8,10^6) = 6499871$. Find $\sum T(a, b, 22332223332233)$ for $2 \le a \le 223$, $2 \le b \le 223$ and $a \neq b$. Give your answer modulo $2233222333$.
<p>Given two unequal positive integers $a$ and $b$, we define a self-describing sequence consisting of alternating runs of $a$s and $b$s. The first element is $a$ and the sequence of run lengths is the original sequence.</p> <p>For $a=2, b=3$, the sequence is: $$2, 2, 3, 3, 2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2, 2, 3, 3, 3, 2, 2, 2, 3, 3, 3,...$$ The sequence begins with <b>two</b> $2$s and <b>two</b> $3$s, then <b>three</b> $2$s and <b>three</b> $3$s, so the run lengths $2, 2, 3, 3, ...$ are given by the original sequence.</p> <p>Let $T(a, b, N)$ be the sum of the first $N$ elements of the sequence. You are given $T(2,3,10) = 25$, $T(4,2,10^4) = 30004$, $T(5,8,10^6) = 6499871$.</p> <p>Find $\sum T(a, b, 22332223332233)$ for $2 \le a \le 223$, $2 \le b \le 223$ and $a \neq b$. Give your answer modulo $2233222333$.</p>
https://projecteuler.net/problem=943
1038733707
944
Given a set $E$ of positive integers, an element $x$ of $E$ is called an element divisor (elevisor) of $E$ if $x$ divides another element of $E$. The sum of all elevisors of $E$ is denoted $\operatorname{sev}(E)$. For example, $\operatorname{sev}(\{1, 2, 5, 6\}) = 1 + 2 = 3$. Let $S(n)$ be the sum of $\operatorname{sev}(E)$ for all subsets $E$ of $\{1, 2, \dots, n\}$. You are given $S(10) = 4927$. Find $S(10^{14}) \bmod 1234567891$.
<p> Given a set $E$ of positive integers, an element $x$ of $E$ is called an <dfn>element divisor (elevisor)</dfn> of $E$ if $x$ divides <b>another</b> element of $E$.</p> <p> The sum of all elevisors of $E$ is denoted $\operatorname{sev}(E)$.<br> For example, $\operatorname{sev}(\{1, 2, 5, 6\}) = 1 + 2 = 3$.</p> <p> Let $S(n)$ be the sum of $\operatorname{sev}(E)$ for all subsets $E$ of $\{1, 2, \dots, n\}$.<br> You are given $S(10) = 4927$.</p> <p> Find $S(10^{14}) \bmod 1234567891$.</p>
https://projecteuler.net/problem=944
1228599511
945
We use $x\oplus y$ for the bitwise XOR of $x$ and $y$. Define the XOR-product of $x$ and $y$, denoted by $x \otimes y$, similar to a long multiplication in base $2$, except that the intermediate results are XORed instead of the usual integer addition. For example, $7 \otimes 3 = 9$, or in base $2$, $111_2 \otimes 11_2 = 1001_2$: $$\begin{align*} \phantom{\otimes 111} 111_2 \\ \otimes \phantom{1111} 11_2 \\ \hline \phantom{\otimes 111} 111_2 \\ \oplus \phantom{11} 111_2 \phantom{9} \\ \hline \phantom{\otimes 11} 1001_2 \\ \end{align*}$$ We consider the equation: $$\begin{align} (a \otimes a) \oplus (2 \otimes a \otimes b) \oplus (b \otimes b) = c \otimes c \end{align}$$ For example, $(a, b, c) = (1, 2, 1)$ is a solution to this equation, and so is $(1, 8, 13)$. Let $F(N)$ be the number of solutions to this equation satisfying $0 \le a \le b \le N$. You are given $F(10)=21$. Find $F(10^7)$.
We use $x\oplus y$ for the bitwise XOR of $x$ and $y$.<br> Define the <dfn>XOR-product</dfn> of $x$ and $y$, denoted by $x \otimes y$, similar to a long multiplication in base $2$, except that the intermediate results are XORed instead of the usual integer addition.<br> For example, $7 \otimes 3 = 9$, or in base $2$, $111_2 \otimes 11_2 = 1001_2$: <center> $$\begin{align*} \phantom{\otimes 111} 111_2 \\ \otimes \phantom{1111} 11_2 \\ \hline \phantom{\otimes 111} 111_2 \\ \oplus \phantom{11} 111_2 \phantom{9} \\ \hline \phantom{\otimes 11} 1001_2 \\ \end{align*}$$ </center> We consider the equation: <center> $$\begin{align} (a \otimes a) \oplus (2 \otimes a \otimes b) \oplus (b \otimes b) = c \otimes c \end{align}$$ </center> <p> For example, $(a, b, c) = (1, 2, 1)$ is a solution to this equation, and so is $(1, 8, 13)$. </p><p> Let $F(N)$ be the number of solutions to this equation satisfying $0 \le a \le b \le N$. You are given $F(10)=21$. </p><p> Find $F(10^7)$. </p>
https://projecteuler.net/problem=945
83357132
946
Given the representation of a continued fraction $$ a_0+ \cfrac 1{a_1+ \cfrac 1{a_2+\cfrac 1{a_3+\ddots }}}= [a_0;a_1,a_2,a_3,\ldots] $$ $\alpha$ is a real number with continued fraction representation: $\alpha = [2;1,1,2,1,1,1,2,1,1,1,1,1,2,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,2,\ldots]$ where the number of $1$'s between each of the $2$'s are consecutive prime numbers. $\beta$ is another real number defined as $$ \beta = \frac{2\alpha+3}{3\alpha+2} $$ The first ten coefficients of the continued fraction of $\beta$ are $[0;1,5,6,16,9,1,10,16,11]$ with sum $75$. Find the sum of the first $10^8$ coefficients of the continued fraction of $\beta$.
<p>Given the representation of a continued fraction $$ a_0+ \cfrac 1{a_1+ \cfrac 1{a_2+\cfrac 1{a_3+\ddots }}}= [a_0;a_1,a_2,a_3,\ldots] $$</p> <p> $\alpha$ is a real number with continued fraction representation: $\alpha = [2;1,1,2,1,1,1,2,1,1,1,1,1,2,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,2,\ldots]$<br> where the number of $1$'s between each of the $2$'s are consecutive prime numbers.</p> <p> $\beta$ is another real number defined as $$ \beta = \frac{2\alpha+3}{3\alpha+2} $$</p> <p> The first ten coefficients of the continued fraction of $\beta$ are $[0;1,5,6,16,9,1,10,16,11]$ with sum $75$.</p> <p> Find the sum of the first $10^8$ coefficients of the continued fraction of $\beta$.</p>
https://projecteuler.net/problem=946
585787007
947
The $(a,b,m)$-sequence, where $0 \leq a,b \lt m$, is defined as $\begin{align*} g(0)&=a\\ g(1)&=b\\ g(n)&= \big(g(n-1) + g(n-2)\big) \bmod m \end{align*}$ All $(a,b,m)$-sequences are periodic with period denoted by $p(a,b,m)$. The first few terms of the $(0,1,8)$-sequence are $(0,1,1,2,3,5,0,5,5,2,7,1,0,1,1,2,\ldots )$ and so $p(0,1,8)=12$. Let $\displaystyle s(m)=\sum_{a=0}^{m-1}\sum_{b=0}^{m-1} p(a,b,m)^2$. For example, $s(3)=513$ and $s(10)=225820$. Define $\displaystyle S(M)=\sum_{m=1}^{M}s(m)$. You are given, $S(3)=542$ and $S(10)=310897$. Find $S(10^6)$. Give your answer modulo $999\,999\,893$.
<p> The $(a,b,m)$-sequence, where $0 \leq a,b \lt m$, is defined as</p> <div style="text-align:center;"> $\begin{align*} g(0)&amp;=a\\ g(1)&amp;=b\\ g(n)&amp;= \big(g(n-1) + g(n-2)\big) \bmod m \end{align*}$ </div> <p> All $(a,b,m)$-sequences are periodic with period denoted by $p(a,b,m)$.<br> The first few terms of the $(0,1,8)$-sequence are $(0,1,1,2,3,5,0,5,5,2,7,1,0,1,1,2,\ldots )$ and so $p(0,1,8)=12$.</p> <p> Let $\displaystyle s(m)=\sum_{a=0}^{m-1}\sum_{b=0}^{m-1} p(a,b,m)^2$. For example, $s(3)=513$ and $s(10)=225820$.</p> <p> Define $\displaystyle S(M)=\sum_{m=1}^{M}s(m)$. You are given, $S(3)=542$ and $S(10)=310897$.</p> <p> Find $S(10^6)$. Give your answer modulo $999\,999\,893$.</p>
https://projecteuler.net/problem=947
213731313
948
Left and Right play a game with a word consisting of L's and R's, alternating turns. On Left's turn, Left can remove any positive number of letters, but not all the letters, from the left side of the word. Right does the same on Right's turn except that Right removes letters from the right side. The game continues until only one letter remains: if it is an 'L' then Left wins; if it is an 'R' then Right wins. Let $F(n)$ be the number of words of length $n$ where the player moving first, whether it's Left or Right, will win the game if both play optimally. You are given $F(3)=4$ and $F(8)=181$. Find $F(60)$.
<p>Left and Right play a game with a word consisting of L's and R's, alternating turns. On Left's turn, Left can remove any positive number of letters, but not all the letters, from the left side of the word. Right does the same on Right's turn except that Right removes letters from the right side. The game continues until only one letter remains: if it is an 'L' then Left wins; if it is an 'R' then Right wins.</p> <p>Let $F(n)$ be the number of words of length $n$ where the player moving first, whether it's Left or Right, will win the game if both play optimally.</p> <p>You are given $F(3)=4$ and $F(8)=181$.</p> <p>Find $F(60)$.</p>
https://projecteuler.net/problem=948
1033654680825334184
949
Left and Right play a game with a number of words, each consisting of L's and R's, alternating turns. On Left's turn, for each word, Left can remove any number of letters (possibly zero), but not all the letters, from the left side of the word. However, at least one letter must be removed from at least one word. Right does the same on Right's turn except that Right removes letters from the right side of each word. The game continues until each word is reduced to a single letter. If there are more L's than R's remaining then Left wins; otherwise if there are more R's than L's then Right wins. In this problem we only consider games with an odd number of words, thus making ties impossible. Let $G(n, k)$ be the number of ways of choosing $k$ words of length $n$, for which Right has a winning strategy when Left plays first. Different orderings of the same set of words are to be counted separately. It can be seen that $G(2, 3)=14$ due to the following solutions (and their reorderings): $$\begin{align} (\texttt{LL},\texttt{RR},\texttt{RR})&:3\text{ orderings}\\ (\texttt{LR},\texttt{LR},\texttt{LR})&:1\text{ ordering}\\ (\texttt{LR},\texttt{LR},\texttt{RR})&:3\text{ orderings}\\ (\texttt{LR},\texttt{RR},\texttt{RR})&:3\text{ orderings}\\ (\texttt{RL},\texttt{RR},\texttt{RR})&:3\text{ orderings}\\ (\texttt{RR},\texttt{RR},\texttt{RR})&:1\text{ ordering} \end{align} $$You are also given $G(4, 3)=496$ and $G(8, 5)=26359197010$. Find $G(20, 7)$ giving your answer modulo $1001001011$.
<p>Left and Right play a game with a number of words, each consisting of L's and R's, alternating turns. On Left's turn, <b>for each word</b>, Left can remove any number of letters (possibly zero), but not all the letters, from the left side of the word. However, at least one letter must be removed from at least one word. Right does the same on Right's turn except that Right removes letters from the right side of each word. The game continues until each word is reduced to a single letter. If there are more L's than R's remaining then Left wins; otherwise if there are more R's than L's then Right wins. In this problem we only consider games with an odd number of words, thus making ties impossible.</p> <p>Let $G(n, k)$ be the number of ways of choosing $k$ words of length $n$, for which Right has a winning strategy when Left plays first. Different orderings of the same set of words are to be counted separately.</p> <p>It can be seen that $G(2, 3)=14$ due to the following solutions (and their reorderings): $$\begin{align} (\texttt{LL},\texttt{RR},\texttt{RR})&amp;:3\text{ orderings}\\ (\texttt{LR},\texttt{LR},\texttt{LR})&amp;:1\text{ ordering}\\ (\texttt{LR},\texttt{LR},\texttt{RR})&amp;:3\text{ orderings}\\ (\texttt{LR},\texttt{RR},\texttt{RR})&amp;:3\text{ orderings}\\ (\texttt{RL},\texttt{RR},\texttt{RR})&amp;:3\text{ orderings}\\ (\texttt{RR},\texttt{RR},\texttt{RR})&amp;:1\text{ ordering} \end{align} $$You are also given $G(4, 3)=496$ and $G(8, 5)=26359197010$.</p> <p>Find $G(20, 7)$ giving your answer modulo $1001001011$.</p>
https://projecteuler.net/problem=949
726010935
950
A band of pirates has come into a hoard of treasure, and must decide how to distribute it amongst themselves. The treasure consists of identical, indivisible gold coins. According to pirate law, the distribution of treasure must proceed as follows: - The most senior pirate proposes a distribution of the coins. - All pirates, including the most senior, vote on whether to accept the distribution. - If at least half of the pirates vote to accept, the distribution stands. - Otherwise, the most senior pirate must walk the plank, and the process resumes from step 1 with the next most senior pirate proposing another distribution. The happiness of a pirate is equal to $-\infty$ if he doesn't survive; otherwise, it is equal to $c + p\cdot w$, where $c$ is the number of coins that pirate receives in the distribution, $w$ is the total number of pirates who were made to walk the plank, and $p$ is the bloodthirstiness of the pirate. The pirates have a number of characteristics: - Greed: to maximise their happiness. - Ruthlessness: incapable of cooperation, making promises or maintaining any kind of reputation. - Shrewdness: perfectly rational and logical. Consider the happiness $c(n,C,p) + p\cdot w(n,C,p)$ of the most senior surviving pirate in the situation where $n$ pirates, all with equal bloodthirstiness $p$, have found $C$ coins. For example, $c(5,5,\frac{1}{10}) = 3$ and $w(5,5,\frac{1}{10})=0$ because it can be shown that if the most senior pirate proposes a distribution of $3,0,1,0,1$ coins to the pirates (in decreasing order of seniority), the three pirates receiving coins will all vote to accept. On the other hand, $c(5,1,\frac{1}{10}) = 0$ and $w(5,1,\frac{1}{10}) = 1$: the most senior pirate cannot survive with any proposal, and then the second most senior pirate must give the only coin to another pirate in order to survive. Define $\displaystyle T(N,C,p) = \sum_{n=1}^N \left ( c(n,C,p) + w(n,C,p) \right )$. You are given that $T(30,3,\frac{1}{\sqrt{3}}) = 190$, $T(50,3,\frac{1}{\sqrt{31}}) = 385$, and $T(10^3, 101, \frac{1}{\sqrt{101}}) = 142427$. Find $\displaystyle \sum_{k=1}^6 T(10^{16},10^k+1,\tfrac{1}{\sqrt{10^k+1}})$. Give the last 9 digits as your answer.
<p>A band of pirates has come into a hoard of treasure, and must decide how to distribute it amongst themselves. The treasure consists of identical, indivisible gold coins.</p> <p>According to pirate law, the distribution of treasure must proceed as follows:</p> <ol> <li>The most senior pirate proposes a distribution of the coins.</li> <li>All pirates, including the most senior, vote on whether to accept the distribution.</li> <li>If at least half of the pirates vote to accept, the distribution stands.</li> <li>Otherwise, the most senior pirate must walk the plank, and the process resumes from step 1 with the next most senior pirate proposing another distribution.</li> </ol> <p>The <i>happiness</i> of a pirate is equal to $-\infty$ if he doesn't survive; otherwise, it is equal to $c + p\cdot w$, where $c$ is the number of coins that pirate receives in the distribution, $w$ is the total number of pirates who were made to walk the plank, and $p$ is the <i>bloodthirstiness</i> of the pirate.</p> <p>The pirates have a number of characteristics:</p> <ul> <li>Greed: to maximise their happiness.</li> <li>Ruthlessness: incapable of cooperation, making promises or maintaining any kind of reputation.</li> <li>Shrewdness: perfectly rational and logical.</li> </ul> <p>Consider the happiness $c(n,C,p) + p\cdot w(n,C,p)$ of the most senior surviving pirate in the situation where $n$ pirates, all with equal bloodthirstiness $p$, have found $C$ coins. For example, $c(5,5,\frac{1}{10}) = 3$ and $w(5,5,\frac{1}{10})=0$ because it can be shown that if the most senior pirate proposes a distribution of $3,0,1,0,1$ coins to the pirates (in decreasing order of seniority), the three pirates receiving coins will all vote to accept. On the other hand, $c(5,1,\frac{1}{10}) = 0$ and $w(5,1,\frac{1}{10}) = 1$: the most senior pirate cannot survive with any proposal, and then the second most senior pirate must give the only coin to another pirate in order to survive.</p> <p>Define $\displaystyle T(N,C,p) = \sum_{n=1}^N \left ( c(n,C,p) + w(n,C,p) \right )$. You are given that $T(30,3,\frac{1}{\sqrt{3}}) = 190$, $T(50,3,\frac{1}{\sqrt{31}}) = 385$, and $T(10^3, 101, \frac{1}{\sqrt{101}}) = 142427$.</p> <p>Find $\displaystyle \sum_{k=1}^6 T(10^{16},10^k+1,\tfrac{1}{\sqrt{10^k+1}})$. Give the last 9 digits as your answer.</p>
https://projecteuler.net/problem=950
429162542
951
Two players play a game using a deck of $2n$ cards: $n$ red and $n$ black. Initially the deck is shuffled into one of the $\binom{2n}{n}$ possible starting configurations. Play then proceeds, alternating turns, where a player follows two steps on each turn: - Remove the top card from the deck, taking note of its colour. - If there is a next card and it is the same colour as the previous card they toss a fair coin. If the coin lands on heads they remove that card as well; otherwise leave it on top of the deck. The player who removes the final card from the deck wins the game. Some starting configurations give an advantage to one of the players; while some starting configurations are fair, in which both players have exactly $50\%$ chance to win the game. For example, if $n=2$ there are four starting configurations which are fair: RRBB, BBRR, RBBR, BRRB. The remaining two, RBRB and BRBR, result in a guaranteed win for the second player. Define $F(n)$ to be the number of starting configurations which are fair. Therefore $F(2)=4$. You are also given $F(8)=11892$. Find $F(26)$.
<p> Two players play a game using a deck of $2n$ cards: $n$ red and $n$ black. Initially the deck is shuffled into one of the $\binom{2n}{n}$ possible starting configurations. Play then proceeds, alternating turns, where a player follows two steps on each turn:</p> <ol> <li> Remove the top card from the deck, taking note of its colour.</li> <li> If there is a next card and it is the same colour as the previous card they toss a fair coin. If the coin lands on heads they remove that card as well; otherwise leave it on top of the deck.</li></ol> <p> The player who removes the final card from the deck wins the game.</p> <p> Some starting configurations give an advantage to one of the players; while some starting configurations are <b>fair</b>, in which both players have exactly $50\%$ chance to win the game. For example, if $n=2$ there are four starting configurations which are fair: RRBB, BBRR, RBBR, BRRB. The remaining two, RBRB and BRBR, result in a guaranteed win for the second player.</p> <p> Define $F(n)$ to be the number of starting configurations which are fair. Therefore $F(2)=4$. You are also given $F(8)=11892$.</p> <p> Find $F(26)$.</p>
https://projecteuler.net/problem=951
495568995495726
952
Given a prime $p$ and a positive integer $n \lt p$, let $R(p, n)$ be the multiplicative order of $p$ modulo $n!$. In other words, $R(p, n)$ is the minimal positive integer $r$ such that $$p^r \equiv 1 \pmod{n!}$$ For example, $R(7, 4) = 2$ and $R(10^9 + 7, 12) = 17280$. Find $R(10^9 + 7, 10^7)$. Give your answer modulo $10^9 + 7$.
<p> Given a prime $p$ and a positive integer $n \lt p$, let $R(p, n)$ be the <b>multiplicative order</b> of $p$ modulo $n!$.<br> In other words, $R(p, n)$ is the minimal positive integer $r$ such that</p> $$p^r \equiv 1 \pmod{n!}$$ <p> For example, $R(7, 4) = 2$ and $R(10^9 + 7, 12) = 17280$.</p> <p> Find $R(10^9 + 7, 10^7)$. Give your answer modulo $10^9 + 7$.</p>
https://projecteuler.net/problem=952
794394453
953
In the classical game of Nim two players take turns removing stones from piles. A player may remove any positive number of stones from a single pile. If there are no remaining stones, the next player to move loses. In Factorisation Nim the initial position of the game is chosen according to the prime factorisation of a given natural number $n$ by setting a pile for each prime factor, including multiplicity. For example, if $n=12=2 \times 2 \times 3$ the game starts with three piles: two piles with two stones and one pile with three stones. It can be verified that the first player to move loses for $n=1$ and for $n=70$, assuming both players play optimally. Let $S(N)$ be the sum of $n$ for $1 \le n \le N$ such that the first player to move loses, assuming both players play optimally. You are given $S(10) = 14$ and $S(100) = 455$. Find $S(10^{14})$. Give your answer modulo $10^9 + 7$.
<p>In the classical game of <b>Nim</b> two players take turns removing stones from piles. A player may remove any positive number of stones from a single pile. If there are no remaining stones, the next player to move loses.</p> <p>In Factorisation Nim the initial position of the game is chosen according to the prime factorisation of a given natural number $n$ by setting a pile for each prime factor, including multiplicity. For example, if $n=12=2 \times 2 \times 3$ the game starts with three piles: two piles with two stones and one pile with three stones.</p> <p>It can be verified that the first player to move loses for $n=1$ and for $n=70$, assuming both players play optimally.</p> <p>Let $S(N)$ be the sum of $n$ for $1 \le n \le N$ such that the first player to move loses, assuming both players play optimally. You are given $S(10) = 14$ and $S(100) = 455$.</p> <p>Find $S(10^{14})$. Give your answer modulo $10^9 + 7$.</p>
https://projecteuler.net/problem=953
176907658
954
A positive integer is called heptaphobic if it is not divisible by seven and no number divisible by seven can be produced by swapping two of its digits. Note that leading zeros are not allowed before or after the swap. For example, $17$ and $1305$ are heptaphobic, but $14$ and $132$ are not because $14$ and $231$ are divisible by seven. Let $C(N)$ count heptaphobic numbers smaller than $N$. You are given $C(100) = 74$ and $C(10^4) = 3737$. Find $C(10^{13})$.
<p>A positive integer is called <i>heptaphobic</i> if it is not divisible by seven and no number divisible by seven can be produced by swapping two of its digits. Note that leading zeros are not allowed before or after the swap.</p> <p>For example, $17$ and $1305$ are heptaphobic, but $14$ and $132$ are not because $14$ and $231$ are divisible by seven.</p> <p>Let $C(N)$ count heptaphobic numbers smaller than $N$. You are given $C(100) = 74$ and $C(10^4) = 3737$.</p> <p>Find $C(10^{13})$.</p>
https://projecteuler.net/problem=954
736463823
955
A sequence $(a_n)_{n \ge 0}$ starts with $a_0 = 3$ and for each $n \ge 0$, - if $a_n$ is a triangle numberA triangle number is a number of the form $m(m + 1)/2$ for some integer $m$., then $a_{n + 1} = a_n + 1$; - otherwise, $a_{n + 1} = 2a_n - a_{n - 1} + 1$. The sequence begins: $${\color{red}3}, 4, {\color{red}6}, 7, 9, 12, 16, {\color{red}21}, 22, 24, 27, 31, {\color{red}36}, 37, 39, 42, \dots$$ where triangle numbers are marked red. The $10$th triangle number in the sequence is $a_{2964} = 1439056$. Find the index $n$ such that $a_n$ is the $70$th triangle number in the sequence.
<p> A sequence $(a_n)_{n \ge 0}$ starts with $a_0 = 3$ and for each $n \ge 0$,</p> <ul> <li>if $a_n$ is a <strong class="tooltip">triangle number<span class="tooltiptext">A triangle number is a number of the form $m(m + 1)/2$ for some integer $m$.</span></strong>, then $a_{n + 1} = a_n + 1$;</li> <li>otherwise, $a_{n + 1} = 2a_n - a_{n - 1} + 1$.</li></ul> <p> The sequence begins: $${\color{red}3}, 4, {\color{red}6}, 7, 9, 12, 16, {\color{red}21}, 22, 24, 27, 31, {\color{red}36}, 37, 39, 42, \dots$$ where triangle numbers are marked red.</p> <p> The $10$th triangle number in the sequence is $a_{2964} = 1439056$.<br> Find the index $n$ such that $a_n$ is the $70$th triangle number in the sequence.</p>
https://projecteuler.net/problem=955
6795261671274
956
The total number of prime factors of $n$, counted with multiplicity, is denoted $\Omega(n)$. For example, $\Omega(12)=3$, counting the factor $2$ twice, and the factor $3$ once. Define $D(n, m)$ to be the sum of all divisors $d$ of $n$ where $\Omega(d)$ is divisible by $m$. For example, $D(24, 3)=1+8+12=21$. The superfactorial of $n$, often written as $n\$$, is defined as the product of the first $n$ factorials: $$n\$=1!\times 2! \times\cdots\times n!$$ The superduperfactorial of $n$, we write as $n\bigstar$, is defined as the product of the first $n$ superfactorials: $$n\bigstar=1\$ \times 2\$ \times\cdots\times n\$ $$ You are given $D(6\bigstar, 6)=6368195719791280$. Find $D(1\,000\bigstar, 1\,000)$. Give your answer modulo $999\,999\,001$.
<p> The total number of prime factors of $n$, counted with multiplicity, is denoted $\Omega(n)$.<br> For example, $\Omega(12)=3$, counting the factor $2$ twice, and the factor $3$ once.</p> <p> Define $D(n, m)$ to be the sum of all divisors $d$ of $n$ where $\Omega(d)$ is divisible by $m$. <br> For example, $D(24, 3)=1+8+12=21$.</p> <p> The <b>superfactorial</b> of $n$, often written as $n\$$, is defined as the product of the first $n$ factorials: $$n\$=1!\times 2! \times\cdots\times n!$$ The <b>superduperfactorial</b> of $n$, we write as $n\bigstar$, is defined as the product of the first $n$ superfactorials: $$n\bigstar=1\$ \times 2\$ \times\cdots\times n\$ $$ </p> <p> You are given $D(6\bigstar, 6)=6368195719791280$.</p> <p> Find $D(1\,000\bigstar, 1\,000)$. Give your answer modulo $999\,999\,001$.</p>
https://projecteuler.net/problem=956
882086212
957
There is a plane on which all points are initially white, except three red points and two blue points. On each day, every line passing through a red point and a blue point is constructed. Then every white point, where two different such lines meet, turns blue. Let $g(n)$ be the maximal possible number of blue points after $n$ days. For example, $g(1)=8$ and $g(2)=28$. Find $g(16)$.
<p> There is a plane on which all points are initially white, except three red points and two blue points.<br> On each day, every line passing through a red point and a blue point is constructed. Then every white point, where two different such lines meet, turns blue.</p> <p> Let $g(n)$ be the maximal possible number of blue points after $n$ days.</p> <p> For example, $g(1)=8$ and $g(2)=28$.</p> <p> Find $g(16)$.</p>
https://projecteuler.net/problem=957
234897386493229284
958
The Euclidean algorithm can be used to find the greatest common divisor of two positive integers. At each step of the algorithm the smaller number is subtracted from the larger one. The algorithm terminates when the numbers are equal, which is then the greatest common divisor of the original numbers. For two numbers $n$ and $m$, let $d(n, m)$ be the number of subtraction steps used by the Euclidean algorithm for computing the greatest common divisor of $n$ and $m$. For a number $n$, let $f(n)$ be the positive number $m$ coprime to $n$ that minimizes $d(n, m)$. If more than one number attains the minimum, the minimal $m$ is chosen. For example, at least four steps are needed for computing the GCD of $7$ and any positive number $m$ coprime to $7$. This number of steps is obtained by $m=2,3,4,5$, yielding $f(7)=2$. You are also given $f(89)=34$ and $f(8191) = 1856$. Find $f(10^{12}+39)$.
<p>The <b>Euclidean algorithm</b> can be used to find the <b>greatest common divisor</b> of two positive integers. At each step of the algorithm the smaller number is subtracted from the larger one. The algorithm terminates when the numbers are equal, which is then the greatest common divisor of the original numbers.</p> <p>For two numbers $n$ and $m$, let $d(n, m)$ be the number of subtraction steps used by the Euclidean algorithm for computing the greatest common divisor of $n$ and $m$.</p> <p>For a number $n$, let $f(n)$ be the positive number $m$ coprime to $n$ that minimizes $d(n, m)$. If more than one number attains the minimum, the minimal $m$ is chosen.</p> <p>For example, at least four steps are needed for computing the GCD of $7$ and any positive number $m$ coprime to $7$. This number of steps is obtained by $m=2,3,4,5$, yielding $f(7)=2$. You are also given $f(89)=34$ and $f(8191) = 1856$.</p> <p>Find $f(10^{12}+39)$.</p>
https://projecteuler.net/problem=958
367554579311
959
A frog is placed on the number line. Every step the frog jumps either $a$ units to the left or $b$ units to the right, both with $1/2$ probability. Define $f(a, b)$ as the limit $\lim_{n \to \infty} \frac{c_n}n$ where $c_n$ is the expected number of unique numbers visited in the first $n$ steps. You are given $f(1, 1) = 0$ and $f(1, 2) \approx 0.427050983$. Find $f(89, 97)$. Give your answer rounded to nine digits after the decimal point.
<p>A frog is placed on the number line. Every step the frog jumps either $a$ units to the left or $b$ units to the right, both with $1/2$ probability.</p> <p>Define $f(a, b)$ as the limit $\lim_{n \to \infty} \frac{c_n}n$ where $c_n$ is the expected number of unique numbers visited in the first $n$ steps. You are given $f(1, 1) = 0$ and $f(1, 2) \approx 0.427050983$.</p> <p>Find $f(89, 97)$. Give your answer rounded to nine digits after the decimal point.</p>
https://projecteuler.net/problem=959
0.857162085
960
There are $n$ distinct piles of stones, each of size $n-1$. Starting with an initial score of $0$, the following procedure is repeated: - Choose any two piles and remove exactly $n$ stones in total from the two piles. - If the number of stones removed from the two piles were $a$ and $b$, add $\min(a,b)$ to the score. If all piles are eventually emptied, the current score is confirmed as final. However, if one gets "stuck" and cannot empty all piles, the current score is discarded, resulting in a final score of $0$. Three example sequences of turns are illustrated below for $n=4$, with each tuple representing pile sizes as one proceeds, and with additions to the score indicated above the arrows. $$ \begin{align} &(3,3,3,3)\xrightarrow{+1}(0,3,2,3)\xrightarrow{+1}(0,3,1,0)\xrightarrow{+1}(0,0,0,0)&:\quad\text{final score }=3\\ &(3,3,3,3)\xrightarrow{+1}(3,0,3,2)\xrightarrow{+2}(1,0,3,0)\xrightarrow{+1}(0,0,0,0)&:\quad\text{final score }=4\\ &(3,3,3,3)\xrightarrow{+2}(1,3,1,3)\xrightarrow{+1}(1,2,1,0)\rightarrow\text{stuck!}&:\quad\text{final score }=0 \end{align} $$ Define $F(n)$ to be the sum of the final scores achieved for every sequence of turns which successfully empty all piles. You are given $F(3)=12$, $F(4)=360$, and $F(8)=16785941760$. Find $F(100)$. Give your answer modulo $10^9+7$.
<p> There are $n$ distinct piles of stones, each of size $n-1$. Starting with an initial score of $0$, the following procedure is repeated:</p> <ol> <li>Choose any two piles and remove exactly $n$ stones in total from the two piles.</li> <li>If the number of stones removed from the two piles were $a$ and $b$, add $\min(a,b)$ to the score.</li></ol> <p> If all piles are eventually emptied, the current score is confirmed as final. However, if one gets "stuck" and cannot empty all piles, the current score is discarded, resulting in a final score of $0$.</p> <p> Three example sequences of turns are illustrated below for $n=4$, with each tuple representing pile sizes as one proceeds, and with additions to the score indicated above the arrows. $$ \begin{align} &amp;(3,3,3,3)\xrightarrow{+1}(0,3,2,3)\xrightarrow{+1}(0,3,1,0)\xrightarrow{+1}(0,0,0,0)&amp;:\quad\text{final score }=3\\ &amp;(3,3,3,3)\xrightarrow{+1}(3,0,3,2)\xrightarrow{+2}(1,0,3,0)\xrightarrow{+1}(0,0,0,0)&amp;:\quad\text{final score }=4\\ &amp;(3,3,3,3)\xrightarrow{+2}(1,3,1,3)\xrightarrow{+1}(1,2,1,0)\rightarrow\text{stuck!}&amp;:\quad\text{final score }=0 \end{align} $$</p> <p> Define $F(n)$ to be the sum of the final scores achieved for every sequence of turns which successfully empty all piles.</p> <p> You are given $F(3)=12$, $F(4)=360$, and $F(8)=16785941760$.</p> <p> Find $F(100)$. Give your answer modulo $10^9+7$.</p>
https://projecteuler.net/problem=960
243559751
961
This game starts with a positive integer. Two players take turns to remove a single digit from that integer. After the digit is removed any resulting leading zeros are removed. For example, removing a digit from $105$ results in either $5$, $10$ or $15$. The winner is the person who removes the last nonzero digit. Define $W(N)$ to be how many positive integers less than $N$ for which the first player can guarantee a win given optimal play. You are given $W(100) = 18$ and $W(10^4) = 1656$. Find $W(10^{18})$.
<p> This game starts with a positive integer. Two players take turns to remove a single digit from that integer. After the digit is removed any resulting leading zeros are removed.</p> <p> For example, removing a digit from $105$ results in either $5$, $10$ or $15$.</p> <p> The winner is the person who removes the last nonzero digit.</p> <p> Define $W(N)$ to be how many positive integers less than $N$ for which the first player can guarantee a win given optimal play. You are given $W(100) = 18$ and $W(10^4) = 1656$.</p> <p> Find $W(10^{18})$.</p>
https://projecteuler.net/problem=961
166666666689036288
962
Given is an integer sided triangle $ABC$ with $BC \le AC \le AB$. $k$ is the angular bisector of angle $ACB$. $m$ is the tangent at $C$ to the circumscribed circle of $ABC$. $n$ is a line parallel to $m$ through $B$. The intersection of $n$ and $k$ is called $E$. How many triangles $ABC$ with a perimeter not exceeding $1\,000\,000$ exist such that $CE$ has integral length? Note: This problem is a more difficult version of Problem 296. Please pay close attention to the differences between the two statements.
<p> Given is an integer sided triangle $ABC$ with $BC \le AC \le AB$.<br>$k$ is the angular bisector of angle $ACB$.<br>$m$ is the tangent at $C$ to the circumscribed circle of $ABC$.<br>$n$ is a line parallel to $m$ through $B$.<br> The intersection of $n$ and $k$ is called $E$. </p> <div align="center"><img src="resources/images/0296_bisector.gif?1678992056" class="dark_img" alt="0296_bisector.gif"></div> <p> How many triangles $ABC$ with a perimeter not exceeding $1\,000\,000$ exist such that $CE$ has integral length?</p> <p class="note"><b>Note</b>: This problem is a more difficult version of <a href="problem=296">Problem 296</a>. Please pay close attention to the differences between the two statements.</p>
https://projecteuler.net/problem=962
7259046
963
NOTE: This problem is related to Problem 882. It is recommended to solve that problem before doing this one. Two players are playing a game. When the game starts, each player holds a paper with two positive integers written on it. They make moves in turn. At a player's turn, the player can do one of the following: - pick a number on the player's own paper and change it by removing a $0$ from its ternary expansionbase-$3$ expansion; - pick a number on the opponent's paper and change it by removing a $1$ from its ternary expansion; - pick a number on either paper and change it by removing a $2$ from its ternary expansion. The player that is unable to make a move loses. Leading zeros are not allowed in any ternary expansion; in particular nobody can make a move on the number $0$. An initial setting is called fair if whichever player moves first will lose the game if both play optimally. For example, if initially the integers on the paper of the first player are $1, 5$ and those on the paper of the second player are $2, 4$, then this is a fair initial setting, which we can denote as $(1, 5 \mid 2, 4)$. Note that the order of the two integers on a paper does not matter, but the order of the two papers matter. Thus $(5, 1 \mid 4, 2)$ is considered the same as $(1, 5 \mid 2, 4)$, while $(2, 4 \mid 1, 5)$ is a different initial setting. Let $F(N)$ be the number of fair initial settings where each initial number does not exceed $N$. For example, $F(5) = 21$. Find $F(10^5)$.
<p class="note"><b>NOTE</b>: This problem is related to <a href="problem=882">Problem 882</a>. It is recommended to solve that problem before doing this one.</p> <p> Two players are playing a game. When the game starts, each player holds a paper with two positive integers written on it.<br> They make moves in turn. At a player's turn, the player can do one of the following:</p> <ul> <li>pick a number on the player's own paper and change it by removing a $0$ from its <strong class="tooltip">ternary expansion<span class="tooltiptext">base-$3$ expansion</span></strong>;</li> <li>pick a number on the opponent's paper and change it by removing a $1$ from its ternary expansion;</li> <li>pick a number on either paper and change it by removing a $2$ from its ternary expansion.</li></ul> <p> The player that is unable to make a move loses.<br> Leading zeros are not allowed in any ternary expansion; in particular nobody can make a move on the number $0$.</p> <p> An initial setting is called <dfn>fair</dfn> if whichever player moves first will lose the game if both play optimally.</p> <p> For example, if initially the integers on the paper of the first player are $1, 5$ and those on the paper of the second player are $2, 4$, then this is a fair initial setting, which we can denote as $(1, 5 \mid 2, 4)$.<br> Note that the order of the two integers on a paper does not matter, but the order of the two papers matter.<br> Thus $(5, 1 \mid 4, 2)$ is considered the same as $(1, 5 \mid 2, 4)$, while $(2, 4 \mid 1, 5)$ is a different initial setting.</p> <p> Let $F(N)$ be the number of fair initial settings where each initial number does not exceed $N$.<br> For example, $F(5) = 21$.</p> <p> Find $F(10^5)$.</p>
https://projecteuler.net/problem=963
55129975871328418
964
A group of $k(k-1) / 2 + 1$ children play a game of $k$ rounds. At the beginning, they are all seated on chairs arranged in a circle. During the $i$-th round: - The music starts playing and $i$ children are randomly selected, with all combinations being equally likely. The selected children stand up and dance around. - When the music stops, these $i$ children sit back down randomly in the $i$ available chairs, with all permutations being equally likely. Let $P(k)$ be the probability that every child ends up sitting exactly one chair to the right of their original chair when the game ends (at the end of the $k$-th round). You are given $P(3) \approx 1.3888888889 \mathrm {e}{-2}$. Find $P(7)$. Give your answer in scientific notation rounded to ten significant digits after the decimal point. Use a lowercase e to separate the mantissa and the exponent.
<p>A group of $k(k-1) / 2 + 1$ children play a game of $k$ rounds.<br> At the beginning, they are all seated on chairs arranged in a circle.</p> <p>During the $i$-th round:</p> <ol> <li>The music starts playing and $i$ children are randomly selected, with all combinations being equally likely. The selected children stand up and dance around.</li> <li>When the music stops, these $i$ children sit back down randomly in the $i$ available chairs, with all permutations being equally likely.</li> </ol> <p>Let $P(k)$ be the probability that every child ends up sitting exactly one chair to the right of their original chair when the game ends (at the end of the $k$-th round).</p> <p>You are given $P(3) \approx 1.3888888889 \mathrm {e}{-2}$.</p> <p>Find $P(7)$. Give your answer in scientific notation rounded to ten significant digits after the decimal point. Use a lowercase e to separate the mantissa and the exponent.</p>
https://projecteuler.net/problem=964
4.7126135532e-29
965
Let $\{x\}$ denote the fractional part of a real number $x$. Define $f_N(x)$ to be the minimal value of $\{nx\}$ for integer $n$ satisfying $0 < n \le N$. Further define $F(N)$ to be the expected value of $f_N(x)$ when $x$ is sampled uniformly in $[0, 1]$. You are given $F(1) = \frac{1}{2}$, $F(4) = \frac{1}{4}$ and $F(10) \approx 0.1319444444444$. Find $F(10^4)$ and give your answer rounded to 13 digits after the decimal point.
<p>Let $\{x\}$ denote the fractional part of a real number $x$.</p> <p>Define $f_N(x)$ to be the <b>minimal</b> value of $\{nx\}$ for integer $n$ satisfying $0 &lt; n \le N$.<br> Further define $F(N)$ to be the expected value of $f_N(x)$ when $x$ is sampled uniformly in $[0, 1]$.</p> <p>You are given $F(1) = \frac{1}{2}$, $F(4) = \frac{1}{4}$ and $F(10) \approx 0.1319444444444$.</p> <p>Find $F(10^4)$ and give your answer rounded to 13 digits after the decimal point.</p>
https://projecteuler.net/problem=965
0.0003452201133
966
Let $I(a, b, c)$ be the largest possible area of intersection between a triangle of side lengths $a, b, c$ and a circle which has the same area as the triangle. For example $I(3, 4, 5) \approx 4.593049$ and $I(3, 4, 6) \approx 3.552564$. Find the sum of $I(a, b, c)$ for integers $a, b, c$ such that $1 \le a \le b \le c \lt a + b$ and $a + b + c \le 200$. Give your answer rounded to two digits after the decimal point.
<p> Let $I(a, b, c)$ be the largest possible area of intersection between a triangle of side lengths $a, b, c$ and a circle which has the same area as the triangle.<br> For example $I(3, 4, 5) \approx 4.593049$ and $I(3, 4, 6) \approx 3.552564$.</p> <p> Find the sum of $I(a, b, c)$ for integers $a, b, c$ such that $1 \le a \le b \le c \lt a + b$ and $a + b + c \le 200$.<br> Give your answer rounded to two digits after the decimal point.</p>
https://projecteuler.net/problem=966
29337152.09
967
A positive integer $n$ is considered $B$-trivisible if the sum of all different prime factors of $n$ which are not larger than $B$ is divisible by $3$. For example, $175 = 5^2 \cdot 7$ is $10$-trivisible because $5 + 7 = 12$ which is divisible by $3$. Similarly, $175$ is $4$-trivisible because all primes dividing $175$ are larger than $4$, and the empty summation $0$ is divisible by $3$. On the other hand, $175$ is not $6$-trivisible because the sum of relevant primes is $5$ which is not divisible by $3$. Let $F(N, B)$ be the number of $B$-trivisible integers not larger than $N$. For example, $F(10, 4) = 5$, the $4$-trivisible numbers being $1,3,5,7,9$. You are also given $F(10, 10) = 3$ and $F(100, 10) = 41$. Find $F(10^{18}, 120)$.
<p> A positive integer $n$ is considered <i>$B$-trivisible</i> if the sum of all different prime factors of $n$ which are not larger than $B$ is divisible by $3$.</p> <p> For example, $175 = 5^2 \cdot 7$ is $10$-trivisible because $5 + 7 = 12$ which is divisible by $3$. Similarly, $175$ is $4$-trivisible because all primes dividing $175$ are larger than $4$, and the empty summation $0$ is divisible by $3$.<br> On the other hand, $175$ is not $6$-trivisible because the sum of relevant primes is $5$ which is not divisible by $3$.</p> <p> Let $F(N, B)$ be the number of $B$-trivisible integers not larger than $N$.</p> <p> For example, $F(10, 4) = 5$, the $4$-trivisible numbers being $1,3,5,7,9$.<br> You are also given $F(10, 10) = 3$ and $F(100, 10) = 41$.</p> <p> Find $F(10^{18}, 120)$.</p>
https://projecteuler.net/problem=967
357591131712034236
968
Define $$P(X_{a,b},X_{a,c},X_{a,d},X_{a,e},X_{b,c},X_{b,d},X_{b,e},X_{c,d},X_{c,e},X_{d,e})$$ as the sum of $2^a3^b5^c7^d11^e$ over all quintuples of non-negative integers $(a, b, c, d, e)$ such that the sum of each two of the five variables is restricted by a given value. In other words, $a+b \le X_{a,b}$, $a+d \le X_{a,d}$, $b+e \le X_{b,e}$ etc. For example, $P(2,2,2,2,2,2,2,2,2,2)=7120$ and $P(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) \equiv 799809376 \pmod{10^9 + 7}$. Define a sequence $A$ as follows: - $A_0 = 1$, $A_1 = 7$; - $A_n =(7A_{n−1}+A_{n-2}^2) \bmod(10^9+7)$ for $n \ge 2$. Also define $Q(n) = P(A_{10n}, A_{10n+1}, A_{10n+2}, \dots , A_{10n+9})$. Find $\displaystyle\sum_{0 \le n \lt 100}Q(n)$. Give your answer modulo $10^9+7$.
<p> Define $$P(X_{a,b},X_{a,c},X_{a,d},X_{a,e},X_{b,c},X_{b,d},X_{b,e},X_{c,d},X_{c,e},X_{d,e})$$ as the sum of $2^a3^b5^c7^d11^e$ over all quintuples of non-negative integers $(a, b, c, d, e)$ such that the sum of each two of the five variables is restricted by a given value. In other words, $a+b \le X_{a,b}$, $a+d \le X_{a,d}$, $b+e \le X_{b,e}$ etc.</p> <p> For example, $P(2,2,2,2,2,2,2,2,2,2)=7120$ and $P(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) \equiv 799809376 \pmod{10^9 + 7}$.</p> <p> Define a sequence $A$ as follows:</p> <ul> <li>$A_0 = 1$, $A_1 = 7$;</li> <li>$A_n =(7A_{n−1}+A_{n-2}^2) \bmod(10^9+7)$ for $n \ge 2$.</li></ul> <p> Also define $Q(n) = P(A_{10n}, A_{10n+1}, A_{10n+2}, \dots , A_{10n+9})$.</p> <p> Find $\displaystyle\sum_{0 \le n \lt 100}Q(n)$. Give your answer modulo $10^9+7$.</p>
https://projecteuler.net/problem=968
885362394
969
Starting at zero, a kangaroo hops along the real number line in the positive direction. Each successive hop takes the kangaroo forward a uniformly random distance between $0$ and $1$. Let $H(n)$ be the expected number of hops needed for the kangaroo to pass $n$ on the real line. If we write $\alpha = H(1)$, then for all positive integers $n$, $H(n)$ can be expressed as a polynomial function of $\alpha$ with rational coefficients. For example $H(3)=\alpha^3-2\alpha^2+\frac{1}{2}\alpha$. Define $S(n)$ to be the sum of all integer coefficients in this polynomial form of $H(n)$. Therefore $S(1)=1$ and $S(3)=1+(-2)=-1$. You are also given $\displaystyle \sum_{n=1}^{10} S(n)=43$. Find $\displaystyle\sum_{n=1}^{10^{18}} S(n)$. Give your answer modulo $10^9+7$.
<p> Starting at zero, a kangaroo hops along the real number line in the positive direction. Each successive hop takes the kangaroo forward a uniformly random distance between $0$ and $1$. Let $H(n)$ be the expected number of hops needed for the kangaroo to pass $n$ on the real line. </p> <p> If we write $\alpha = H(1)$, then for all positive integers $n$, $H(n)$ can be expressed as a polynomial function of $\alpha$ with rational coefficients. For example $H(3)=\alpha^3-2\alpha^2+\frac{1}{2}\alpha$. Define $S(n)$ to be the sum of all <b>integer</b> coefficients in this polynomial form of $H(n)$. Therefore $S(1)=1$ and $S(3)=1+(-2)=-1$.<br> You are also given $\displaystyle \sum_{n=1}^{10} S(n)=43$.<br> Find $\displaystyle\sum_{n=1}^{10^{18}} S(n)$. Give your answer modulo $10^9+7$. </p>
https://projecteuler.net/problem=969
412543690
970
Starting at zero, a kangaroo hops along the real number line in the positive direction. Each successive hop takes the kangaroo forward a uniformly random distance between $0$ and $1$. Let $H(n)$ be the expected number of hops needed for the kangaroo to pass $n$ on the real line. For example, $H(2) \approx 4.67077427047$. The first eight digits after the decimal point that are different from six are $70774270$. Similarly, $H(3) \approx 6.6665656395558899$. Here the first eight digits after the decimal point that are different from six are $55395558$. Find $H(10^6)$ and give as your answer the first eight digits after the decimal point that are different from six.
<p> Starting at zero, a kangaroo hops along the real number line in the positive direction. Each successive hop takes the kangaroo forward a uniformly random distance between $0$ and $1$. Let $H(n)$ be the expected number of hops needed for the kangaroo to pass $n$ on the real line. </p> <p> For example, $H(2) \approx 4.67077427047$. The first eight digits after the decimal point that are different from six are $70774270$. </p> <p> Similarly, $H(3) \approx 6.6665656395558899$. Here the first eight digits after the decimal point that are different from six are $55395558$. </p> <p> Find $H(10^6)$ and give as your answer the first eight digits after the decimal point that are different from six. </p>
https://projecteuler.net/problem=970
44754029
971
Let $p$ be a prime of the form $5k-4$ and define $f_p(x) = \left(x^k+x\right) \bmod p$. Let $C(p)$ be the number of values $0 \le x \lt p$ such that $f_p^{(m)}(x) = x$ for some positive integer $m$, that is, $x$ can be obtained by iteratively applying $f_p$ on itself starting at $x$. For example, $C(11) = 7$, due to $x = 0, 1, 2, 3, 8, 9, 10$. Let $S(N)$ be the sum of $C(p)$ for all primes of the form $5k-4$ not exceeding $N$. For example $S(100) = 127$. Find $S(10^8)$.
<p>Let $p$ be a prime of the form $5k-4$ and define $f_p(x) = \left(x^k+x\right) \bmod p$.</p> <p>Let $C(p)$ be the number of values $0 \le x \lt p$ such that $f_p^{(m)}(x) = x$ for some positive integer $m$, that is, $x$ can be obtained by iteratively applying $f_p$ on itself starting at $x$.</p> <p>For example, $C(11) = 7$, due to $x = 0, 1, 2, 3, 8, 9, 10$.</p> <p>Let $S(N)$ be the sum of $C(p)$ for all primes of the form $5k-4$ not exceeding $N$. For example $S(100) = 127$.</p> <p>Find $S(10^8)$.</p>
https://projecteuler.net/problem=971
33626723890930
972
The hyperbolic plane can be represented by the open unit disc, namely the set of points $(x, y)$ in $\Bbb R^2$ with $x^2 + y^2 < 1$. A geodesic is defined as either a diameter of the open unit disc or a circular arc contained within the disc that is orthogonal to the boundary of the disc. The following diagram shows the hyperbolic plane with two geodesics; one is a diameter and the other is a circular arc. Let $\mathcal V(N)$ be the set of points $(x, y)$ such that $x^2 + y^2 \lt 1$ and $x, y$ are both rational numbers with denominator not exceeding $N$. Let $T(N)$ be the number of ordered triples $(P, Q, R)$ such that $P, Q, R$ are three different points in $\mathcal V(N)$ and there is a hyperbolic line passing through all of them. For example, $T(2) = 24$ and $T(3) = 1296$. Find $T(12)$.
<p> The <b>hyperbolic plane</b> can be represented by the <b>open unit disc</b>, namely the set of points $(x, y)$ in $\Bbb R^2$ with $x^2 + y^2 &lt; 1$.</p> <p> A <b>geodesic</b> is defined as either a diameter of the open unit disc or a circular arc contained within the disc that is orthogonal to the boundary of the disc.<br> The following diagram shows the hyperbolic plane with two geodesics; one is a diameter and the other is a circular arc.</p> <div align="center"><img src="resources/images/0972_hyperbolic.png?1762877126" alt="0972_hyperbolic.png"></div> <p> Let $\mathcal V(N)$ be the set of points $(x, y)$ such that $x^2 + y^2 \lt 1$ and $x, y$ are both rational numbers with denominator not exceeding $N$.</p> <p> Let $T(N)$ be the number of ordered triples $(P, Q, R)$ such that $P, Q, R$ are three different points in $\mathcal V(N)$ and there is a hyperbolic line passing through all of them.<br> For example, $T(2) = 24$ and $T(3) = 1296$.</p> <p> Find $T(12)$.</p>
https://projecteuler.net/problem=972
3575508
973
A game is played with $n$ cards. At the start the cards are dealt out onto a table to get $n$ piles of size one. Each round proceeds as follows: - Select a pile at random and pick it up. - Randomly choose a pile from the table and add the top card of the picked-up pile to it. - Redistribute any remaining cards from the picked-up pile by dealing them into new single-card piles. The game ends when all cards are in a single pile. At the end of each round a score is obtained by bitwise-XORing the size of each pile. The score is summed across the rounds. Let $X(n)$ be the expected total score at the end of the game. You are given $X(2) = 2$, $X(4) = 14$ and $X(10) = 1418$. Find $X(10^4)$. Give your answer modulo $10^9+7$.
<p> A game is played with $n$ cards. At the start the cards are dealt out onto a table to get $n$ piles of size one.</p> <p> Each round proceeds as follows:</p> <ol> <li>Select a pile at random and pick it up.</li> <li>Randomly choose a pile from the table and add the top card of the picked-up pile to it.</li> <li>Redistribute any remaining cards from the picked-up pile by dealing them into new single-card piles.</li></ol> <p> The game ends when all cards are in a single pile.</p> <p> At the end of each round a score is obtained by bitwise-XORing the size of each pile. The score is summed across the rounds. Let $X(n)$ be the expected total score at the end of the game.</p> <p> You are given $X(2) = 2$, $X(4) = 14$ and $X(10) = 1418$.</p> <p> Find $X(10^4)$. Give your answer modulo $10^9+7$.</p>
https://projecteuler.net/problem=973
427278142
974
A very odd number is a number which contains only odd digits and is divisible by $105$. Further each odd digit occurs an odd number of times. Define $\Theta (n)$ be the $n$th very odd number, then $\Theta (1) = 1117935$ and $\Theta(10^3) = 11137955115$. Find $\Theta(10^{16})$.
<p> A <i>very odd number</i> is a number which contains only odd digits and is divisible by $105$. Further each odd digit occurs an odd number of times.</p> <p> Define $\Theta (n)$ be the $n$th very odd number, then $\Theta (1) = 1117935$ and $\Theta(10^3) = 11137955115$.</p> <p> Find $\Theta(10^{16})$.</p>
https://projecteuler.net/problem=974
13313751171933973557517973175
975
Given a pair $(a,b)$ of coprime odd positive integers, define the function $$H_{a,b}(x)=\frac{1}{2}-\frac{1}{2(a+b)}\Bigl(b\cos(a\pi x)+a\cos(b\pi x)\Bigr) $$It can be seen that $H_{a,b}(0)=0$, $H_{a,b}(1)=1$, and $0 < H_{a,b}(x) < 1$ for all $x$ strictly between $0$ and $1$. Given two such pairs $(a,b)$ and $(c,d)$, paths of infinitesimal width traverse the unit cube internally through every point $(x,y,z)\in [0,1]^3$ such that $z=H_{a,b}(x)=H_{c,d}(y)$. Remarkably, it can be shown that the point $(0,0,0)$ is always connected to the opposite corner $(1,1,1)$. Furthermore, with the additional condition $\gcd(a+b,c+d)\in\{2,4\}$, it can be shown that there is exactly one path connecting the two points. Shown above are two examples, as viewed from above the cube. That is, we see the paths projected onto the $xy$-plane, with corresponding $z$ values indicated with varying colour. In the second example some paths are coloured grey to indicate that, while they exist, they do not form part of the path from $(0,0,0)$ to $(1,1,1)$. Define $F(a, b, c, d)$ to be the sum of the absolute changes in height (or $z$-coordinate) over all uphill and downhill sections of the path from $(0,0,0)$ to $(1,1,1)$. In the first example above, the path climbs $\approx4.00886$ over eleven uphill sections, and descends $\approx3.00886$ over ten downhill sections, giving $F(3,5,3,7)\approx7.01772$. You are also given $F(7,17,9,19)\approx 26.79578$. Let $G(m, n)$ be the sum of $F(p,q,p,2q-p)$ over all pairs $(p,q)$ of primes, $m\leq p < q\leq n$. You are given $G(3, 20)\approx463.80866$. Find $G(500,1000)$ giving your answer rounded to five digits after the decimal point.
<p> Given a pair $(a,b)$ of <b>coprime odd positive integers</b>, define the function $$H_{a,b}(x)=\frac{1}{2}-\frac{1}{2(a+b)}\Bigl(b\cos(a\pi x)+a\cos(b\pi x)\Bigr) $$It can be seen that $H_{a,b}(0)=0$, $H_{a,b}(1)=1$, and $0 &lt; H_{a,b}(x) &lt; 1$ for all $x$ strictly between $0$ and $1$. </p><p> Given two such pairs $(a,b)$ and $(c,d)$, paths of infinitesimal width traverse the unit cube internally through every point $(x,y,z)\in [0,1]^3$ such that $z=H_{a,b}(x)=H_{c,d}(y)$. Remarkably, it can be shown that the point $(0,0,0)$ is always connected to the opposite corner $(1,1,1)$. Furthermore, with the additional condition $\gcd(a+b,c+d)\in\{2,4\}$, it can be shown that there is exactly one path connecting the two points. </p> <div align="center"><img src="resources/images/0975_examples.png?1763356593" alt="0975_examples.png"></div> <p> Shown above are two examples, as viewed from above the cube. That is, we see the paths projected onto the $xy$-plane, with corresponding $z$ values indicated with varying colour. In the second example some paths are coloured grey to indicate that, while they exist, they do not form part of the path from $(0,0,0)$ to $(1,1,1)$. </p> <p> Define $F(a, b, c, d)$ to be the sum of the absolute changes in height (or $z$-coordinate) over all uphill and downhill sections of the path from $(0,0,0)$ to $(1,1,1)$. In the first example above, the path climbs $\approx4.00886$ over eleven uphill sections, and descends $\approx3.00886$ over ten downhill sections, giving $F(3,5,3,7)\approx7.01772$. You are also given $F(7,17,9,19)\approx 26.79578$. </p> <p> Let $G(m, n)$ be the sum of $F(p,q,p,2q-p)$ over all pairs $(p,q)$ of primes, $m\leq p &lt; q\leq n$. You are given $G(3, 20)\approx463.80866$. </p><p> Find $G(500,1000)$ giving your answer rounded to five digits after the decimal point. </p>
https://projecteuler.net/problem=975
88597366.47748
976
Two players X and O play a game with $k$ strips of squares of lengths $n_1,\dots,n_k$, originally all blank. Starting with X, they make moves in turn. At X's turn, X draws an "X" symbol; at O's turn, O draws an "O" symbol. The symbol must be drawn in one blank square with either red or blue pen, subject to the following restrictions: - two symbols in adjacent squares on one strip must be different symbols and must have different colour; - if there is at least one blank strip, then one must draw on a blank strip. Whoever does not have a valid move loses the game. Let $P(K, N)$ be the number of tuples $(n_1,\dots,n_k)$ such that $1 \leq k \leq K$, $1\leq n_1\leq\cdots\leq n_k\leq N$ and that X has a winning strategy to the corresponding game. For example, $P(2, 4)=7$ and $P(5, 10) = 901$. Find $P(10^7, 10^7)\bmod 1234567891$.
<p> Two players X and O play a game with $k$ strips of squares of lengths $n_1,\dots,n_k$, originally all blank.</p> <p> Starting with X, they make moves in turn. At X's turn, X draws an "X" symbol; at O's turn, O draws an "O" symbol.<br> The symbol must be drawn in one blank square with either red or blue pen, subject to the following restrictions:</p> <ol> <li>two symbols in adjacent squares on one strip must be different symbols <b>and</b> must have different colour;</li> <li>if there is at least one blank strip, then one must draw on a blank strip.</li></ol> <p> Whoever does not have a valid move loses the game.</p> <p> Let $P(K, N)$ be the number of tuples $(n_1,\dots,n_k)$ such that $1 \leq k \leq K$, $1\leq n_1\leq\cdots\leq n_k\leq N$ and that X has a winning strategy to the corresponding game.<br> For example, $P(2, 4)=7$ and $P(5, 10) = 901$.</p> <p> Find $P(10^7, 10^7)\bmod 1234567891$.</p>
https://projecteuler.net/problem=976
675608326
977
For a positive integer $n$, let $F(n)$ denote the number of functions $f$ from the set $S_n=\{1,2,\dots,n\}$ to itself such that $f^{(x)}(y)=f^{(y)}(x)$ for any $x,y$ in $S_n$. Here $f^{(k)}$ denotes the $k$-th iterated composition of $f$, e.g. $f^{(2)}(x)=f(f(x))$. For example, $F(3)=8$, $F(7)=174$, $F(100)=570271270297640131$. Find $F(10^6) \bmod (10^9+7)$.
<p>For a positive integer $n$, let $F(n)$ denote the number of functions $f$ from the set $S_n=\{1,2,\dots,n\}$ to itself such that $f^{(x)}(y)=f^{(y)}(x)$ for any $x,y$ in $S_n$. Here $f^{(k)}$ denotes the $k$-th iterated composition of $f$, e.g. $f^{(2)}(x)=f(f(x))$.</p> <p>For example, $F(3)=8$, $F(7)=174$, $F(100)=570271270297640131$.</p> <p>Find $F(10^6) \bmod (10^9+7)$.</p>
https://projecteuler.net/problem=977
537945304
978
In this problem we consider a random walk on the integers $\mathbb{Z}$, in which our position at time $t$ is denoted as $X_t$. At time $0$ we start at position $0$. That is, $X_0=0$. At time $1$ we jump to position $1$. That is, $X_1=1$. Thereafter, at time $t=2,3,\dots$ we make a jump of size $|X_{t-2}|$ in either the positive or negative direction, with probability $1/2$ each way. If $X_{t-2}=0$ we stay put at time $t$. At $t=5$ we find our position $X_5$ has the following distribution: $$ X_5=\begin{cases} -1\quad&\text{with probability }3/8\\ 1\quad&\text{with probability }3/8\\ 3\quad&\text{with probability }1/8\\ 5\quad&\text{with probability }1/8\\ \end{cases} $$ The standard deviation $\sigma$ of a random variable $X$ with mean $\mu$ is defined as $$ \sigma=\sqrt{\mathbb{E}[X^2]-\mu^2} $$ Furthermore the skewness of $X$ is defined as $$ \text{Skew}(X)=\mathbb{E}\biggl[\Bigl(\frac{X-\mu}{\sigma}\Bigr)^3\biggr] $$ For $X_5$, which has mean $1$ and standard deviation $2$, we find $\text{Skew}(X_5)=0.75$. You are also given $\text{Skew}(X_{10})\approx2.50997097$. Find $\text{Skew}(X_{50})$. Give your answer rounded to eight digits after the decimal point.
<p> In this problem we consider a <b>random walk</b> on the integers $\mathbb{Z}$, in which our position at time $t$ is denoted as $X_t$. </p> <p> At time $0$ we start at position $0$. That is, $X_0=0$.<br> At time $1$ we jump to position $1$. That is, $X_1=1$.<br> Thereafter, at time $t=2,3,\dots$ we make a jump of size $|X_{t-2}|$ in either the positive or negative direction, with probability $1/2$ each way. If $X_{t-2}=0$ we stay put at time $t$. </p> <p> At $t=5$ we find our position $X_5$ has the following distribution: $$ X_5=\begin{cases} -1\quad&amp;\text{with probability }3/8\\ 1\quad&amp;\text{with probability }3/8\\ 3\quad&amp;\text{with probability }1/8\\ 5\quad&amp;\text{with probability }1/8\\ \end{cases} $$ The <b>standard deviation</b> $\sigma$ of a <b>random variable</b> $X$ with <b>mean</b> $\mu$ is defined as $$ \sigma=\sqrt{\mathbb{E}[X^2]-\mu^2} $$ Furthermore the <b>skewness</b> of $X$ is defined as $$ \text{Skew}(X)=\mathbb{E}\biggl[\Bigl(\frac{X-\mu}{\sigma}\Bigr)^3\biggr] $$ For $X_5$, which has mean $1$ and standard deviation $2$, we find $\text{Skew}(X_5)=0.75$. You are also given $\text{Skew}(X_{10})\approx2.50997097$. </p> <p> Find $\text{Skew}(X_{50})$. Give your answer rounded to eight digits after the decimal point. </p>
https://projecteuler.net/problem=978
254.54470757
979
The hyperbolic plane, represented by the open unit disc, can be tiled by heptagons. Every tile is a hyperbolic heptagon (i.e. it has seven edges which are segments of geodesics in the hyperbolic plane) and every vertex is shared by three tiles. Please refer to Problem 972 for some of the definitions. The diagram below shows an illustration of this tiling. Now, a hyperbolic frog starts from one of the heptagons, as shown in the diagram. At each step, it can jump to any one of the seven adjacent tiles. Define $F(n)$ to be the number of paths the frog can trace so that after $n$ steps it lands back at the starting tile. You are given $F(4) = 119$. Find $F(20)$.
<p>The <b>hyperbolic plane</b>, represented by the <b>open unit disc</b>, can be tiled by heptagons. Every tile is a hyperbolic heptagon (i.e. it has seven edges which are segments of <b>geodesics</b> in the hyperbolic plane) and every vertex is shared by three tiles.<br> Please refer to <a href="problem=972">Problem 972</a> for some of the definitions.</p> <p>The diagram below shows an illustration of this tiling.</p> <div align="center"><img src="resources/images/0979_heptagons_frog.png?1767857959" alt="0979_heptagons_frog.png" width="500"></div> <p>Now, a hyperbolic frog starts from one of the heptagons, as shown in the diagram. At each step, it can jump to any one of the seven adjacent tiles.</p> <p>Define $F(n)$ to be the number of paths the frog can trace so that after $n$ steps it lands back at the starting tile.<br> You are given $F(4) = 119$.</p> <p>Find $F(20)$.</p>
https://projecteuler.net/problem=979
189306828278449
980
Starting from an empty string, we want to build a string with letters "x", "y", "z". At each step, one of the following operations is performed: - insert two consecutive identical letters "xx", "yy" or "zz" anywhere into the string; - replace one letter in the string with two consecutive letters, according to the rule: "x" $\to$ "yz", "y" $\to$ "zx", "z" $\to$ "xy"; - exchange two consecutive different letters in the string, e.g. "xy" $\to$ "yx", "zx" $\to$ "xz", etc. A string is called neutral if it is possible to produce the string from the empty string after an even number of steps. We define a sequence $(a_n)_{n \ge 0}$: $a_0=88\,888\,888$ and $a_n=(8888\cdot a_{n-1})\bmod 888\,888\,883$ for $n \gt 0$. Let $b_n = a_n \bmod 3$. For each $i \ge 0$, a string $c(i)$ of length $50$ is defined by translating the finite sequence $b_{50i},b_{50i+1},\dots,b_{50i+49}$ via the rule: $0 \to$ "x", $1 \to$ "y", $2 \to$ "z". Let $F(N)$ be the number of ordered pairs $(i, j)$ with $0 \le i, j \lt N$ such that the concatenated string $c(i)c(j)$ is neutral. For example, $F(10) = 13$ and $F(100) = 1224$. Find $F(10^6)$.
<p> Starting from an empty string, we want to build a string with letters "x", "y", "z". At each step, one of the following operations is performed:</p> <ul> <li>insert two consecutive identical letters "xx", "yy" or "zz" anywhere into the string;</li> <li>replace one letter in the string with two consecutive letters, according to the rule: "x" $\to$ "yz", "y" $\to$ "zx", "z" $\to$ "xy";</li> <li>exchange two consecutive <b>different</b> letters in the string, e.g. "xy" $\to$ "yx", "zx" $\to$ "xz", etc.</li></ul> <p> A string is called <dfn>neutral</dfn> if it is possible to produce the string from the empty string after an <b>even</b> number of steps.</p> <p> We define a sequence $(a_n)_{n \ge 0}$: $a_0=88\,888\,888$ and $a_n=(8888\cdot a_{n-1})\bmod 888\,888\,883$ for $n \gt 0$.</p> <p> Let $b_n = a_n \bmod 3$. For each $i \ge 0$, a string $c(i)$ of length $50$ is defined by translating the finite sequence $b_{50i},b_{50i+1},\dots,b_{50i+49}$ via the rule: $0 \to$ "x", $1 \to$ "y", $2 \to$ "z".</p> <p> Let $F(N)$ be the number of ordered pairs $(i, j)$ with $0 \le i, j \lt N$ such that the concatenated string $c(i)c(j)$ is neutral.<br> For example, $F(10) = 13$ and $F(100) = 1224$.</p> <p> Find $F(10^6)$.</p>
https://projecteuler.net/problem=980
124999683766
981
Starting from an empty string, we want to build a string with letters "x", "y", "z". At each step, one of the following operations is performed: - insert two consecutive identical letters "xx", "yy" or "zz" anywhere into the string; - replace one letter in the string with two consecutive letters, according to the rule: "x" $\to$ "yz", "y" $\to$ "zx", "z" $\to$ "xy"; - exchange two consecutive different letters in the string, e.g. "xy" $\to$ "yx", "zx" $\to$ "xz", etc. A string is called neutral if it is possible to produce the string from the empty string after an even number of steps. Let $N(X, Y, Z)$ be the number of neutral strings which contain $X$ copies of "x", $Y$ copies of "y" and $Z$ copies of "z". For example, $N(2, 2, 2) = 42$ and $N(8, 8, 8) = 4732773210$. Find the sum of $N(i^3, j^3, k^3)$ for $0 \le i, j, k \lt 88$. Give your answer modulo $888\,888\,883$.
<p> Starting from an empty string, we want to build a string with letters "x", "y", "z". At each step, one of the following operations is performed:</p> <ul> <li>insert two consecutive identical letters "xx", "yy" or "zz" anywhere into the string;</li> <li>replace one letter in the string with two consecutive letters, according to the rule: "x" $\to$ "yz", "y" $\to$ "zx", "z" $\to$ "xy";</li> <li>exchange two consecutive <b>different</b> letters in the string, e.g. "xy" $\to$ "yx", "zx" $\to$ "xz", etc.</li></ul> <p> A string is called <dfn>neutral</dfn> if it is possible to produce the string from the empty string after an <b>even</b> number of steps.</p> <p> Let $N(X, Y, Z)$ be the number of neutral strings which contain $X$ copies of "x", $Y$ copies of "y" and $Z$ copies of "z".<br> For example, $N(2, 2, 2) = 42$ and $N(8, 8, 8) = 4732773210$.</p> <p> Find the sum of $N(i^3, j^3, k^3)$ for $0 \le i, j, k \lt 88$. Give your answer modulo $888\,888\,883$.</p>
https://projecteuler.net/problem=981
794963735