Let $S_k$ be the set containing $2$ and $5$ and the first $k$ primes that end in $7$. For example, $S_3 = \{2,5,7,17,37\}$.

Define a $k$-Ruff number to be one that is not divisible by any element in $S_k$.

If $N_k$ is the product of the numbers in $S_k$ then define $F(k)$ to be the sum of all $k$-Ruff numbers less than $N_k$ that have last digit $7$. You are given $F(3) = 76101452$.

Find $F(97)$, give your answer modulo $1\,000\,000\,007$.

Answer: 556206950


Let '$\&$' denote the bitwise AND operation.

For example, $10\,\&\, 12 = 1010_2\,\&\, 1100_2 = 1000_2 = 8$.

We shall call a finite sequence of non-negative integers $(a_1, a_2, \ldots, a_n)$ conjunctive if $a_i\,\&\, a_{i+1} \neq 0$ for all $i=1\ldots n-1$.

Define $c(n,b)$ to be the number of conjunctive sequences of length $n$ in which all terms are $\le b$.

You are given that $c(3,4)=18$, $c(10,6)=2496120$, and $c(100,200) \equiv 268159379 \pmod {998244353}$.

Find $c(123,123456789)$. Give your answer modulo $998244353$.

Answer: 459155763


When wrapping several cubes in paper, it is more efficient to wrap them all together than to wrap each one individually. For example, with 10 cubes of unit edge length, it would take 30 units of paper to wrap them in the arrangement shown below, but 60 units to wrap them separately.

Define $g(n)$ to be the maximum amount of paper that can be saved by wrapping $n$ identical $1\times 1\times 1$ cubes in a compact arrangement, compared with wrapping them individually. We insist that the wrapping paper is in contact with the cubes at all points, without leaving a void.

With $10$ cubes, the arrangement illustrated above is optimal, so $g(10)=60-30=30$. With $18$ cubes, it can be shown that the optimal arrangement is as a $3\times 3\times 2$, using $42$ units of paper, whereas wrapping individually would use $108$ units of paper; hence $g(18) = 66$.

Define
$$G(N) = \sum_{n=1}^N g(n).$$
You are given that $G(18) = 530$, and $G(10^6) \equiv 951640919 \pmod {1\,000\,000\,007}$.

Find $G(10^{16})$. Give your answer modulo $1\,000\,000\,007$.

Answer: 946791106


For a positive integer $n$, $d(n)$ is defined to be the sum of the digits of $n$. For example, $d(12345)=15$.

Let $\displaystyle F(N)=\sum_{n=1}^N \frac n{d(n)}$.

You are given $F(10)=19$, $F(123)\approx 1.187764610390\mathrm e3$ and $F(12345)\approx 4.855801996238\mathrm e6$.

Find $F(1234567890123456789)$. Write your answer in scientific notation rounded to twelve significant digits after the decimal point. Use a lowercase e to separate the mantissa and the exponent.

Answer: 9.627509725002e33


For coprime positive integers $a$ and $b$, let $C_{a,b}$ be the curve defined by:
$$
\begin{align}
x &= \cos \left(at\right) \\
y &= \cos \left(b\left(t-\frac{\pi}{10}\right)\right)
\end{align}
$$
where $t$ varies between $0$ and $2\pi$.

For example, the images below show $C_{2,5}$ (left) and $C_{7,4}$ (right):

Define $d(a,b) = \sum (x^2 + y^2)$, where the sum is over all points (x, y) at which $C_{a,b}$ crosses itself.

For example, in the case of $C_{2,5}$ illustrated above, the curve crosses itself at two points: $(0.31, 0)$ and $(-0.81, 0)$, rounding coordinates to two decimal places, yielding $d(2, 5)=0.75$. Some other examples are $d(2,3)=4.5$, $d(7,4)=39.5$, $d(7,5)=52$, and $d(10,7)=23.25$.

Let $s(m) = \sum d(a,b)$, where this sum is over all pairs of coprime integers $a,b$ with $2\le a\le m$ and $2\le b\le m$.

You are given that $s(10) = 1602.5$ and $s(100) = 24256505$.

Find $s(10^6)$. Give your answer in scientific notation rounded to $10$ significant digits; for example $s(100)$ would be given as 2.425650500e7.

Answer: 2.533018434e23


If $a,b$ are two nonnegative integers with decimal representations $a=(\dots a_2a_1a_0)$ and $b=(\dots b_2b_1b_0)$ respectively, then the freshman's product of $a$ and $b$, denoted $a\boxtimes b$, is the integer $c$ with decimal representation $c=(\dots c_2c_1c_0)$ such that $c_i$ is the last digit of $a_i\cdot b_i$.

For example, $234 \boxtimes 765 = 480$.

Let $F(R,M)$ be the sum of $x_1 \boxtimes \dots \boxtimes x_R$ for all sequences of integers $(x_1,\dots,x_R)$ with $0\leq x_i \leq M$.

For example, $F(2, 7) = 204$, and $F(23, 76) \equiv 5870548 \pmod{ 1\,000\,000\,009}$.

Find $F(234567,765432)$. Give your answer modulo $1\,000\,000\,009$.

Answer: 146133880


For a positive integer $n \gt 1$, let $p(n)$ be the smallest prime dividing $n$, and let $\alpha(n)$ be its $p$-adic order, i.e. the largest integer such that $p(n)^{\alpha(n)}$ divides $n$.

For a positive integer $K$, define the function $f_K(n)$ by:
$$f_K(n)=\frac{\alpha(n)-1}{(p(n))^K}.$$

Also define $\overline{f_K}$ by:
$$\overline{f_K}=\lim_{N \to \infty} \frac{1}{N}\sum_{n=2}^{N} f_K(n).$$

It can be verified that $\overline{f_1} \approx 0.282419756159$.

Find $\displaystyle \sum_{K=1}^{\infty}\overline{f_K}$. Give your answer rounded to $12$ digits after the decimal point.

Answer: 0.547326103833


For positive real numbers $a,b$, an $a\times b$ torus is a rectangle of width $a$ and height $b$, with left and right sides identified, as well as top and bottom sides identified. In other words, when tracing a path on the rectangle, reaching an edge results in "wrapping round" to the corresponding point on the opposite edge.

A tiling of a torus is a way to dissect it into equilateral triangles of edge length 1. For example, the following three diagrams illustrate respectively a $1\times \frac{\sqrt{3}}{2}$ torus with two triangles, a $\sqrt{3}\times 1$ torus with four triangles, and an approximately $2.8432\times 2.1322$ torus with fourteen triangles:

Two tilings of an $a\times b$ torus are called equivalent if it is possible to obtain one from the other by continuously moving all triangles so that no gaps appear and no triangles overlap at any stage during the movement. For example, the animation below shows an equivalence between two tilings:

Let $F(n)$ be the total number of non-equivalent tilings of all possible tori with exactly $n$ triangles. For example, $F(6)=8$, with the eight non-equivalent tilings with six triangles listed below:

Let $G(N)=\sum_{n=1}^N F(n)$. You are given that $G(6)=14$, $G(100)=8090$, and $G(10^5)\equiv 645124048 \pmod{1\,000\,000\,007}$.

Find $G(10^9)$. Give your answer modulo $1\,000\,000\,007$.

Answer: 613979935


Let $F(n)$ be the number of connected graphs with blue edges (directed) and red edges (undirected) containing:

- two vertices of degree $1$, one with a single outgoing blue edge and the other with a single incoming blue edge.

- $n$ vertices of degree $3$, each of which has an incoming blue edge, a different outgoing blue edge and a red edge.

For example, $F(4)=5$ because there are $5$ graphs with these properties:

You are also given $F(8)=319$.

Find $F(50\,000)$. Give your answer modulo $1\,000\,000\,007$.

NOTE: Feynman diagrams are a way of visualising the forces between elementary particles. Vertices represent interactions. The blue edges in our diagrams represent matter particles (e.g. electrons or positrons) with the arrow representing the flow of charge. The red edges (normally wavy lines) represent the force particles (e.g. photons). Feynman diagrams are used to predict the strength of particle interactions.

Answer: 162450870


The complexity of an $n\times n$ binary matrix is the number of distinct rows and columns.

For example, consider the $3\times 3$ matrices
$$		\mathbf{A} = \begin{pmatrix} 1&0&1\\0&0&0\\1&0&1\end{pmatrix}	\quad
\mathbf{B} = \begin{pmatrix} 0&0&0\\0&0&0\\1&1&1\end{pmatrix}	$$
$\mathbf{A}$ has complexity $2$ because the set of rows and columns is $\{000,101\}$.
$\mathbf{B}$ has complexity $3$ because the set of rows and columns is $\{000,001,111\}$.

For $0 \le k \le n^2$, let $c(n, k)$ be the minimum complexity of an $n\times n$ binary matrix with exactly $k$ ones.

Let
$$C(n) = \sum_{k=0}^{n^2} c(n, k)$$
For example, $C(2) = c(2, 0) + c(2, 1) + c(2, 2) + c(2, 3) + c(2, 4) = 1 + 2 + 2 + 2 + 1 = 8$.

You are given $C(5) = 64$, $C(10) = 274$ and $C(20) = 1150$.

Find $C(10^4)$.

Answer: 318313204


Given $n$ and $k$ two positive integers we begin with an urn that contains $kn$ white balls. We then proceed through $n$ turns where on each turn $k$ black balls are added to the urn and then $2k$ random balls are removed from the urn.

We let $B_t(n,k)$ be the number of black balls that are removed on turn $t$.

Further define $E(n,k)$ as the expectation of $\displaystyle \sum_{t=1}^n B_t(n,k)^2$.

You are given $E(2,2) = 9.6$.

Find $E(10^6,10)$. Round your answer to the nearest whole number.

Answer: 136666597


Let's call a pair of positive integers $p$, $q$ ($p \lt q$) reciprocal, if there is a positive integer $r\lt p$ such that $r$ equals both the inverse of $p$ modulo $q$ and the inverse of $q$ modulo $p$.

For example, $(3,5)$ is one reciprocal pair for $r=2$.

Let $F(N)$ be the total sum of $p+q$ for all reciprocal pairs $(p,q)$ where $p \le N$.

$F(5)=59$ due to these four reciprocal pairs $(3,5)$, $(4,11)$, $(5,7)$ and $(5,19)$.

You are also given $F(10^2) = 697317$.

Find $F(2\cdot 10^6)$.

Answer: 5833303012576429231


Consider the following Diophantine equation:
$$15  (x^2 + y^2 + z^2) = 34  (xy + yz + zx)$$
where $x$, $y$ and $z$ are positive integers.

Let $S(N)$ be the sum of all solutions, $(x,y,z)$, of this equation such that, $1 \le x \le y \le z \le N$ and $\gcd(x, y, z) = 1$.

For $N = 10^2$, there are three such solutions - $(1, 7, 16), (8, 9, 39), (11, 21, 72)$. So $S(10^2) = 184$.

Find $S(10^9)$.

Answer: 29526986315080920


The following diagram shows a billiard table of a special quadrilateral shape.
The four angles $A, B, C, D$ are $120^\circ, 90^\circ, 60^\circ, 90^\circ$ respectively, and the lengths $AB$ and $AD$ are equal.

The diagram on the left shows the trace of an infinitesimally small billiard ball, departing from point $A$, bouncing twice on the edges of the table, and finally returning back to point $A$. The diagram on the right shows another such trace, but this time bouncing eight times:

The table has no friction and all bounces are perfect elastic collisions.

Note that no bounce should happen on any of the corners, as the behaviour would be unpredictable.

Let $B(N)$ be the number of possible traces of the ball, departing from point $A$, bouncing at most $N$ times on the edges and returning back to point $A$.

For example, $B(10) = 6$, $B(100) = 478$, $B(1000) = 45790$.

Find $B(10^9)$.

Answer: 45594532839912702


Two players play a game with two piles of stones. They take alternating turns. If there are currently $a$ stones in the first pile and $b$ stones in the second, a turn consists of removing $c\geq 0$ stones from the first pile and $d\geq 0$ from the second in such a way that $ad-bc=\pm1$. The winner is the player who first empties one of the piles.

Note that the game is only playable if the sizes of the two piles are coprime.

A game state $(a, b)$ is a winning position if the next player can guarantee a win with optimal play. Define $H(N)$ to be the number of winning positions $(a, b)$ with $\gcd(a,b)=1$, $a > 0$, $b > 0$ and $a+b \leq N$. Note the order matters, so for example $(2,1)$ and $(1,2)$ are distinct positions.

You are given $H(4)=5$ and $H(100)=2043$.

Find $H(10^9)$.

Answer: 202642367520564145


A dominating number is a positive integer that has more than half of its digits equal.

For example, $2022$ is a dominating number because three of its four digits are equal to $2$. But $2021$ is not a dominating number.

Let $D(N)$ be how many dominating numbers are less than $10^N$.
For example, $D(4) = 603$ and $D(10) = 21893256$.

Find $D(2022)$. Give your answer modulo $1\,000\,000\,007$.

Answer: 471745499


Given an odd prime $p$, put the numbers $1,...,p-1$ into $\frac{p-1}{2}$ pairs such that each number appears exactly once. Each pair $(a,b)$ has a cost of $ab \bmod p$. For example, if $p=5$ the pair $(3,4)$ has a cost of $12 \bmod 5 = 2$.

The total cost of a pairing is the sum of the costs of its pairs. We say that such pairing is optimal if its total cost is minimal for that $p$.

For example, if $p = 5$, then there is a unique optimal pairing: $(1, 2), (3, 4)$, with total cost of $2 + 2 = 4$.

The cost product of a pairing is the product of the costs of its pairs. For example, the cost product of the optimal pairing for $p = 5$ is $2 \cdot 2 = 4$.

It turns out that all optimal pairings for $p = 2\,000\,000\,011$ have the same cost product.

Find the value of this product.


There is a grid of length and width $50515093$ points. A clock is placed on each grid point. The clocks are all analogue showing a single hour hand initially pointing at $12$.

A sequence $S_t$ is created where:
$$
\begin{align}
S_0 &= 290797\\
S_t &= S_{t-1}^2 \bmod 50515093 &t>0
\end{align}
$$
The four numbers $N_t = (S_{4t-4}, S_{4t-3}, S_{4t-2}, S_{4t-1})$ represent a range within the grid, with the first pair of numbers representing the x-bounds and the second pair representing the y-bounds. For example, if $N_t = (3,9,47,20)$, the range would be $3\le x\le 9$ and $20\le y\le47$, and would include $196$ clocks.

For each $t$ $(t>0)$, the clocks within the range represented by $N_t$ are moved to the next hour $12\rightarrow 1\rightarrow 2\rightarrow \cdots $.

We define $C(t)$ to be the sum of the hours that the clock hands are pointing to after timestep $t$.

You are given $C(0) = 30621295449583788$, $C(1) =  30613048345941659$, $C(10) = 21808930308198471$ and $C(100) = 16190667393984172$.

Find $C(10^5)$.

Answer: 16585056588495119


Denote the average of $k$ numbers $x_1, ..., x_k$ by $\bar{x} = \frac{1}{k} \sum_i x_i$. Their variance is defined as $\frac{1}{k} \sum_i \left( x_i - \bar{x} \right) ^ 2$.

Let $S(n)$ be the sum of all quadruples of integers $(a,b,c,d)$ satisfying $1 \leq a \leq b \leq c \leq d \leq n$ such that their average is exactly twice their variance.

For $n=5$, there are $5$ such quadruples, namely: $(1, 1, 1, 3), (1, 1, 3, 3), (1, 2, 3, 4), (1, 3, 4, 4), (2, 2, 3, 5)$.

Hence $S(5)=48$. You are also given $S(10^3)=37048340$.

Find $S(10^8)$. Give your answer modulo $433494437$.

Answer: 404890862


We define $\nu_2(n)$ to be the largest integer $r$ such that $2^r$ divides $n$. For example, $\nu_2(24) = 3$.

Define $\displaystyle S(n)  = \sum_{k = 1}^n (-2)^k\binom{2k}k$ and $u(n) = \nu_2\Big(3S(n)+4\Big)$.

For example, when $n = 4$ then $S(4) = 980$ and $3S(4) + 4 = 2944 = 2^7 \cdot 23$, hence $u(4) = 7$.

You are also given $u(20) = 24$.

Also define $\displaystyle U(N) = \sum_{n = 1}^N u(n^3)$. You are given $U(5) = 241$.

Find $U(10^4)$.

Answer: 2500500025183626


Let $S_i$ be an integer sequence produced with the following pseudo-random number generator:

- $S_0 = 290797$

-  $S_{i+1} = S_i ^2 \bmod 50515093$

Let $M(n)$ be the median of the pairwise products $ S_i S_j $ for $0 \le i \lt j \lt n$.

You are given $M(3) = 3878983057768$ and $M(103) = 492700616748525$.

Find $M(1\,000\,003)$.

Answer: 475808650131120


This problem uses half open interval notation where $[a,b)$ represents $a \le x \lt b$.

A real number, $x_1$, is chosen in the interval $[0,1)$.

A second real number, $x_2$, is chosen such that each of $[0,\frac{1}{2})$ and $[\frac{1}{2},1)$ contains exactly one of $(x_1, x_2)$.

Continue such that on the $n$-th step a real number, $x_n$, is chosen so that each of the intervals $[\frac{k-1}{n}, \frac{k}{n})$ for $k \in \{1, \dots, n\}$ contains exactly one of $(x_1, x_2, \dots, x_n)$.

Define $F(n)$ to be the minimal value of the sum $x_1 + x_2 + \cdots + x_n$ of a tuple $(x_1, x_2, \dots, x_n)$ chosen by such a procedure. For example, $F(4) = 1.5$ obtained with $(x_1, x_2, x_3, x_4) = (0, 0.75, 0.5, 0.25)$.

Surprisingly, no more than $17$ points can be chosen by this procedure.

Find $F(17)$ and give your answer rounded to $12$ decimal places.

Answer: 8.146681749623


For a positive integer $n$, the function $g(n)$ is defined as

$$\displaystyle g(n)=\sum_{i=1}^{n} (-1)^i \gcd \left(n,i^2\right).$$

For example, $g(4) = -\gcd \left(4,1^2\right) + \gcd \left(4,2^2\right) - \gcd \left(4,3^2\right) + \gcd \left(4,4^2\right) = -1+4-1+4=6$.

You are also given $g(1234)=1233$.

Let $\displaystyle G(N) = \sum_{n=1}^N g(n)$. You are given $G(1234) = 2194708$.

Find $G(12345678)$.

Answer: 955892601606483


A standard $52$ card deck comprises thirteen ranks in four suits. However, modern decks have two additional Jokers, which neither have a suit nor a rank, for a total of $54$ cards. If we shuffle such a deck and draw cards without replacement, then we would need, on average, approximately $29.05361725$ cards so that we have at least one card for each rank.

Now, assume you have $10$ such decks, each with a different back design. We shuffle all $10 \times 54$ cards together and draw cards without replacement. What is the expected number of cards needed so every suit, rank and deck design have at least one card?

Give your answer rounded to eight places after the decimal point.

Answer: 43.20649061


A monic polynomial is a single-variable polynomial in which the coefficient of highest degree is equal to $1$.

Define $\mathcal{F}$ to be the set of all monic polynomials with integer coefficients (including the constant polynomial $p(x)=1$). A polynomial $p(x)\in\mathcal{F}$ is cyclogenic if there exists $q(x)\in\mathcal{F}$ and a positive integer $n$ such that $p(x)q(x)=x^n-1$. If $n$ is the smallest such positive integer then $p(x)$ is $n$-cyclogenic.

Define $P_n(x)$ to be the sum of all $n$-cyclogenic polynomials. For example, there exist ten 6-cyclogenic polynomials (which divide $x^6-1$ and no smaller $x^k-1$):

$$\begin{align*}
&x^6-1&&x^4+x^3-x-1&&x^3+2x^2+2x+1&&x^2-x+1\\
&x^5+x^4+x^3+x^2+x+1&&x^4-x^3+x-1&&x^3-2x^2+2x-1\\
&x^5-x^4+x^3-x^2+x-1&&x^4+x^2+1&&x^3+1\end{align*}$$
giving

$$P_6(x)=x^6+2x^5+3x^4+5x^3+2x^2+5x.$$
Also define

$$Q_N(x)=\sum_{n=1}^N P_n(x).$$
It's given that
$Q_{10}(x)=x^{10}+3x^9+3x^8+7x^7+8x^6+14x^5+11x^4+18x^3+12x^2+23x$ and $Q_{10}(2) = 5598$.

Find $Q_{10^7}(2)$. Give your answer modulo $1\,000\,000\,007$.

Answer: 47722272


Two players play a game with a deck of cards which contains $s$ suits with each suit containing $n$ cards numbered from $1$ to $n$.

Before the game starts, a set of cards (which may be empty) is picked from the deck and placed face-up on the table, with no overlap. These are called the visible cards.

The players then make moves in turn.

A move consists of choosing a card X from the rest of the deck and placing it face-up on top of a visible card Y, subject to the following restrictions:

- X and Y must be the same suit;

- the value of X must be larger than the value of Y.

The card X then covers the card Y and replaces Y as a visible card.

The player unable to make a valid move loses and play stops.

Let $C(n, s)$ be the number of different initial sets of cards for which the first player will lose given best play for both players.

For example, $C(3, 2) = 26$ and $C(13, 4) \equiv 540318329 \pmod {1\,000\,000\,007}$.

Find $C(10^7, 10^7)$. Give your answer modulo $1\,000\,000\,007$.

Answer: 132996198


Pentagonal numbers are generated by the formula: $P_n = \tfrac 12n(3n-1)$ giving the sequence:

$$1,5,12,22,35, 51,70,92,\ldots $$

Some pentagonal numbers can be expressed as the sum of two other pentagonal numbers.

For example:

$$P_8 = 92 = 22 + 70 = P_4 + P_7$$

$3577$ is the smallest pentagonal number that can be expressed as the sum of two pentagonal numbers in two different ways

$$
\begin{align}
P_{49} = 3577 & = 3432 + 145 = P_{48} + P_{10} \\
& = 3290 + 287 = P_{47}+P_{14}
\end{align}
$$

$107602$ is the smallest pentagonal number that can be expressed as the sum of two pentagonal numbers in three different ways.

Find the smallest pentagonal number that can be expressed as the sum of two pentagonal numbers in over $100$ different ways.

Answer: 1096910149053902


An integer of the form $p^q q^p$ with prime numbers $p \neq q$ is called a hybrid-integer.

For example, $800 = 2^5 5^2$ is a hybrid-integer.

We define $C(n)$ to be the number of hybrid-integers less than or equal to $n$.

You are given $C(800) = 2$ and $C(800^{800}) = 10790$.

Find $C(800800^{800800})$.

Answer: 1412403576


The positive integral solutions of the equation $x^y=y^x$ are $(2,4)$, $(4,2)$ and $(k,k)$ for all $k > 0$.

For a given positive integer $n$, let $f(n)$ be the number of integral values $0 < x,y \leq n^2-n$ such that
$$x^y\equiv y^x \pmod n.$$
For example, $f(5)=104$ and $f(97)=1614336$.

Let $S(M,N)=\sum f(p)$ where the sum is taken over all primes $p$ satisfying $M\le p\le N$.

You are given $S(1,10^2)=7381000$ and $S(1,10^5) \equiv 701331986 \pmod{993353399}$.

Find $S(10^{16}, 10^{16}+10^6)$. Give your answer modulo $993353399$.

Answer: 638129754


Let $\Bbb R^2$ be the set of pairs of real numbers $(x, y)$. Let $\pi = 3.14159\cdots\ $.

Consider the function $f$ from $\Bbb R^2$ to $\Bbb R^2$ defined by $f(x, y) = (x^2 - x - y^2, 2xy - y + \pi)$, and its $n$-th iterated composition $f^{(n)}(x, y) = f(f(\cdots f(x, y)\cdots))$. For example $f^{(3)}(x, y) = f(f(f(x, y)))$. A pair $(x, y)$ is said to have period $n$ if $n$ is the smallest positive integer such that $f^{(n)}(x, y) = (x, y)$.

Let $P(n)$ denote the sum of $x$-coordinates of all points having period not exceeding $n$.
Interestingly, $P(n)$ is always an integer. For example, $P(1) = 2$, $P(2) = 2$, $P(3) = 4$.

Find $P(10^7)$ and give your answer modulo $1\,020\,340\,567$.

Answer: 973873727


Rand48 is a pseudorandom number generator used by some programming languages. It generates a sequence from any given integer $0 \le a_0 < 2^{48}$ using the rule $a_n = (25214903917 \cdot a_{n - 1} + 11) \bmod 2^{48}$.

Let $b_n = \lfloor a_n / 2^{16} \rfloor \bmod 52$.
The sequence $b_0, b_1, \dots$ is translated to an infinite string $c = c_0c_1\dots$ via the rule:

$0 \rightarrow$ a, $1\rightarrow$ b, $\dots$, $25 \rightarrow$ z, $26 \rightarrow$ A, $27 \rightarrow$ B, $\dots$, $51 \rightarrow$ Z.

For example, if we choose $a_0 = 123456$, then the string $c$ starts with: "bQYicNGCY$\dots$".

Moreover, starting from index $100$, we encounter the substring "RxqLBfWzv" for the first time.

Alternatively, if $c$ starts with "EULERcats$\dots$", then $a_0$ must be $78580612777175$.

Now suppose that the string $c$ starts with "PuzzleOne$\dots$".

Find the starting index of the first occurrence of the substring "LuckyText" in $c$.

Answer: 9300900470636


Let $g(n)$ denote the number of ways a positive integer $n$ can be represented in the form: $$x^2+xy+41y^2$$ where $x$ and $y$ are integers. For example, $g(53)=4$ due to $(x,y) \in \{(-4,1),(-3,-1),(3,1),(4,-1)\}$.

Define $\displaystyle T(N)=\sum_{n=1}^{N}g(n)$. You are given $T(10^3)=474$ and $T(10^6)=492128$.

Find $T(10^{16})$.

Answer: 4921370551019052


For a positive integer $n$, let $s(n)$ be the integer obtained by shifting the leftmost digit of the decimal representation of $n$ to the rightmost position.

For example, $s(142857)=428571$ and $s(10)=1$.

For a positive rational number $r$, we define $N(r)$ as the smallest positive integer $n$ such that $s(n)=r\cdot n$.

If no such integer exists, then $N(r)$ is defined as zero.

For example, $N(3)=142857$, $N(\tfrac 1{10})=10$ and $N(2) = 0$.

Let $T(M)$ be the sum of $N(u^3/v^3)$ where $(u,v)$ ranges over all ordered pairs of coprime positive integers not exceeding $M$.

For example, $T(3)\equiv 262429173 \pmod {1\,000\,000\,007}$.

Find $T(200)$. Give your answer modulo $1\,000\,000\,007$.

Answer: 119719335


This problem combines the game of Nim with the Towers of Hanoi. For a brief introduction to the rules of these games, please refer to Problem 301 and Problem 497, respectively.

The unique shortest solution to the Towers of Hanoi problem with $n$ disks and $3$ pegs requires $2^n-1$ moves. Number the positions in the solution from index 0 (starting position, all disks on the first peg) to index $2^n-1$ (final position, all disks on the third peg).

Each of these $2^n$ positions can be considered as the starting configuration for a game of Nim, in which two players take turns to select a peg and remove any positive number of disks from it. The winner is the player who removes the last disk.

We define $f(n)$ to be the sum of the indices of those positions for which, when considered as a Nim game, the first player will lose (assuming an optimal strategy from both players).

For $n=4$, the indices of losing positions in the shortest solution are 3,6,9 and 12. So we have $f(4) = 30$.

You are given that $f(10) = 67518$.

Find $f(10^5)$. Give your answer modulo $1\,000\,000\,007$.

Answer: 94394343


Given a circle $C$ and an integer $n > 1$, we perform the following operations.

In step $0$, we choose two uniformly random points $R_0$ and $B_0$ on $C$.

In step $i$ ($1 \leq i < n$), we first choose a uniformly random point $R_i$ on $C$ and connect the points $R_{i - 1}$ and $R_i$ with a red rope; then choose a uniformly random point $B_i$ on $C$ and connect the points $B_{i - 1}$ and $B_i$ with a blue rope.

In step $n$, we first connect the points $R_{n - 1}$ and $R_0$ with a red rope; then connect the points $B_{n - 1}$ and $B_0$ with a blue rope.

Each rope is straight between its two end points, and lies above all previous ropes.

After step $n$, we get a loop of red ropes, and a loop of blue ropes.

Sometimes the two loops can be separated, as in the left figure below; sometimes they are "linked", hence cannot be separated, as in the middle and right figures below.

Let $P(n)$ be the probability that the two loops can be separated.

For example, $P(3) = \frac{11}{20}$ and $P(5) \approx 0.4304177690$.

Find $P(80)$, rounded to $10$ digits after decimal point.

Answer: 0.1091523673


Both $169$ and $961$ are the square of a prime. $169$ is the reverse of $961$.

We call a number a reversible prime square if:

- It is not a palindrome, and

- It is the square of a prime, and

- Its reverse is also the square of a prime.

$169$ and $961$ are not palindromes, so both are reversible prime squares.

Find the sum of the first $50$ reversible prime squares.

Answer: 3807504276997394


The following is a function defined for all positive rational values of $x$.

$$	f(x)=\begin{cases} x  &x\text{ is integral}\\
f(\frac 1{1-x})	&x \lt 1\\
f\Big(\frac 1{\lceil x\rceil -x}-1+f(x-1)\Big)	&\text{otherwise}\end{cases}	$$

For example, $f(3/2)=3$, $f(1/6) = 65533$ and $f(13/10) = 7625597484985$.

Find $f(22/7)$. Give your answer modulo $10^{15}$.

Answer: 75353432948733


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*}
$$

An XOR-prime is an integer $n$ greater than $1$ that is not an XOR-product of two integers greater than $1$. The above example shows that $9$ is not an XOR-prime. Similarly, $5 = 3 \otimes 3$ is not an XOR-prime. The first few XOR-primes are $2, 3, 7, 11, 13, ...$ and the 10th XOR-prime is $41$.

Find the $5\,000\,000$th XOR-prime.

Answer: 124136381


Let $b(n)$ be the largest power of 2 that divides $n$. For example $b(24) = 8$.

Define the recursive function:
$$\begin{align*}
\begin{split}
A(0) &= 1\\
A(2n) &= 3A(n) + 5A\big(2n - b(n)\big)  \qquad n \gt 0\\
A(2n+1) &= A(n)
\end{split}
\end{align*}$$
and let $H(t,r) = A\big((2^t+1)^r\big)$.

You are given $H(3,2) = A(81) = 636056$.

Find $H(10^{14}+31,62)$. Give your answer modulo $1\,000\,062\,031$.

Answer: 327287526


A dynamical polynomial is a monicleading coefficient is $1$ polynomial $f(x)$ with integer coefficients such that $f(x)$ divides $f(x^2-2)$.

For example, $f(x) = x^2 - x - 2$ is a dynamical polynomial because $f(x^2-2) = x^4-5x^2+4 = (x^2 + x -2)f(x)$.

Let $S(n)$ be the number of dynamical polynomials of degree $n$.

For example, $S(2)=6$, as there are six dynamical polynomials of degree $2$:

$$ x^2-4x+4 \quad,\quad x^2-x-2 \quad,\quad x^2-4 \quad,\quad x^2-1 \quad,\quad x^2+x-1 \quad,\quad x^2+2x+1 $$
Also, $S(5)=58$ and $S(20)=122087$.

Find $S(10\,000)$. Give your answer modulo $998244353$.

Answer: 986262698


We use $x\oplus y$ to be 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, $11 \otimes 11 = 69$, or in base $2$, $1011_2 \otimes 1011_2 = 1000101_2$:

$$
\begin{align*}
\phantom{\otimes 1111} 1011_2 \\
\otimes \phantom{1111} 1011_2 \\
\hline
\phantom{\otimes 1111} 1011_2 \\
\phantom{\otimes 111} 1011_2 \phantom{9} \\
\oplus \phantom{1} 1011_2  \phantom{999} \\
\hline
\phantom{\otimes 11} 1000101_2 \\
\end{align*}
$$
Further we define $P(n) = 11^{\otimes n} = \overbrace{11\otimes 11\otimes \ldots \otimes 11}^n$. For example $P(2)=69$.

Find $P(8^{12}\cdot 12^8)$. Give your answer modulo $10^9+7$.

Answer: 14063639


$4n$ people stand in a circle with their heads down. When the bell rings they all raise their heads and either look at the person immediately to their left, the person immediately to their right or the person diametrically opposite. If two people find themselves looking at each other they both scream.

Define $S(n)$ to be the number of ways that exactly half of the people scream. You are given $S(1) =  48$ and $S(10) \equiv 420121075 \mod{998244353}$.

Find $S(10^3)$. Enter your answer modulo $998244353$.

Answer: 307159326


A pack of cards contains $4n$ cards with four identical cards of each value. The pack is shuffled and cards are dealt one at a time and placed in piles of equal value. If the card has the same value as any pile it is placed in that pile. If there is no pile of that value then it begins a new pile. When a pile has four cards of the same value it is removed.

Throughout the process the maximum number of non empty piles is recorded. Let $E(n)$ be its expected value. You are given $E(2) = 1.97142857$ rounded to 8 decimal places.

Find $E(60)$. Give your answer rounded to 8 digits after the decimal point.

Answer: 54.12691621


We create an array of points  $P_n$ in a two dimensional plane using the following random number generator:

$s_0=290797$

$s_{n+1}={s_n}^2 \bmod 50515093$

$P_n=(s_{2n},s_{2n+1})$

Let $d(k)$  be the shortest distance of any two (distinct) points among $P_0, \cdots, P_{k - 1}$.

E.g. $d(14)=546446.466846479$.

Find $d(2000000)$. Give your answer rounded to $9$ places after the decimal point.

Answer: 20.880613018


Define $m = M(n, d)$ to be the smallest positive integer such that when $m^2$ is written in base $n$ it includes the base $n$ digit $d$. For example, $M(10,7) = 24$ because if all the squares are written out in base 10 the first time the digit 7 occurs is in $24^2 = 576$. $M(11,10) = 19$ as $19^2 = 361=2A9_{11}$.

Find $\displaystyle \sum_{d = 1}^{10^5}M(p, p - d)$ where $p = 10^9 + 7$.

Answer: 93158936107011


The SET® card game is played with a pack of $81$ distinct cards. Each card has four features (Shape, Color, Number, Shading). Each feature has three different variants (e.g. Color can be red, purple, green).

A SET consists of three different cards such that each feature is either the same on each card or different on each card.

For a collection $C_n$ of $n$ cards, let $S(C_n)$ denote the number of SETs in $C_n$. Then define $F(n) = \sum\limits_{C_n} S(C_n)^4$ where $C_n$ ranges through all collections of $n$ cards (among the $81$ cards).
You are given $F(3) = 1080$ and $F(6) = 159690960$.

Find $F(12)$.

$\scriptsize{\text{SET is a registered trademark of Cannei, LLC.  All rights reserved.
Used with permission from PlayMonster, LLC.}}$

Answer: 11871909492066000


Given an $n$-tuple of numbers another $n$-tuple is created where each element of the new $n$-tuple is chosen randomly from the numbers in the previous $n$-tuple. For example, given $(2,2,3)$ the probability that $2$ occurs in the first position in the next 3-tuple is $2/3$. The probability of getting all $2$'s would be $8/27$ while the probability of getting the same 3-tuple (in any order) would be $4/9$.

Let $E(n)$ be the expected number of steps starting with $(1,2,\ldots,n)$ and ending with all numbers being the same.

You are given $E(3) = 27/7$ and $E(5) = 468125/60701 \approx 7.711982$ rounded to 6 digits after the decimal place.

Find $E(10^3)$. Give the answer rounded to 6 digits after the decimal place.

Answer: 1995.975556


Let $d_n(x)$ be the $n$th decimal digit of the fractional part of $x$, or $0$ if the fractional part has fewer than $n$ digits.

For example:

- $d_7 \mathopen{}\left( 1 \right)\mathclose{} = d_7 \mathopen{}\left( \frac 1 2 \right)\mathclose{} = d_7 \mathopen{}\left( \frac 1 4 \right)\mathclose{} = d_7 \mathopen{}\left( \frac 1 5 \right)\mathclose{} = 0$

- $d_7 \mathopen{}\left( \frac 1 3 \right)\mathclose{} = 3$ since $\frac 1 3 =$ 0.3333333333...

- $d_7 \mathopen{}\left( \frac 1 6 \right)\mathclose{} = 6$ since $\frac 1 6 =$ 0.1666666666...

- $d_7 \mathopen{}\left( \frac 1 7 \right)\mathclose{} = 1$ since $\frac 1 7 =$ 0.1428571428...

Let $\displaystyle  S(n) = \sum_{k=1}^n d_n \mathopen{}\left( \frac 1 k \right)\mathclose{}$.

You are given:

- $S(7) = 0 + 0 + 3 + 0 + 0 + 6 + 1 = 10$

- $S(100) = 418$

Find $S(10^7)$.

Answer: 44967734


A set, $S$, of integers is called 123-separable if $S$, $2S$ and $3S$ are disjoint. Here $2S$ and $3S$ are obtained by multiplying all the elements in $S$ by $2$ and $3$ respectively.

Define $F(n)$ to be the maximum number of elements of
$$(S\cup 2S \cup 3S)\cap \{1,2,3,\ldots,n\}$$
where $S$ ranges over all 123-separable sets.

For example, $F(6) = 5$ can be achieved with either $S = \{1,4,5\}$ or $S = \{1,5,6\}$.

You are also given $F(20) = 19$.

Find $F(10^{16})$.

Answer: 9219661511328178


A list initially contains the numbers $2, 3, \dots, n$.

At each round, the smallest number in the list is replaced by its square. If there is more than one such number, then only one of them is replaced.

For example, below are the first three rounds for $n = 5$:
$$[2, 3, 4, 5] \xrightarrow{(1)} [4, 3, 4, 5] \xrightarrow{(2)} [4, 9, 4, 5] \xrightarrow{(3)} [16, 9, 4, 5].$$

Let $S(n, m)$ be the sum of all numbers in the list after $m$ rounds.

For example, $S(5, 3) = 16 + 9 + 4 + 5 = 34$. Also $S(10, 100) \equiv 845339386 \pmod{1234567891}$.

Find $S(10^4, 10^{16})$. Give your answer modulo $1234567891$.

Answer: 950591530


A list initially contains the numbers $2, 3, \dots, n$.

At each round, every number in the list is divided by its smallest prime factor. Then the product of these smallest prime factors is added to the list as a new number. Finally, all numbers that become $1$ are removed from the list.

For example, below are the first three rounds for $n = 5$:
$$[2, 3, 4, 5] \xrightarrow{(1)} [2, 60] \xrightarrow{(2)} [30, 4] \xrightarrow{(3)} [15, 2, 4].$$
Let $S(n, m)$ be the sum of all numbers in the list after $m$ rounds.

For example, $S(5, 3) = 15 + 2 + 4 = 21$. Also $S(10, 100) = 257$.

Find $S(10^4, 10^{16})$. Give your answer modulo $1234567891$.

Answer: 865849519


A Slider is a chess piece that can move one square left or right.

This problem uses a cylindrical chess board where the left hand edge of the board is connected to the right hand edge. This means that a Slider that is on the left hand edge of the chess board can move to the right hand edge of the same row and vice versa.

Let $L(N,K)$ be the number of ways $K$ non-attacking Sliders can be placed on an $N \times N$ cylindrical chess-board.

For example, $L(2,2)=4$ and $L(6,12)=4204761$.

Find $L(10^9,10^{15}) \bmod \left(10^7+19\right)^2$.

Answer: 26532152736197


Two cars are on a circular track of total length $2n$, facing the same direction, initially distance $n$ apart.

They move in turn. At each turn, the moving car will advance a distance of $1$, $2$ or $3$, with equal probabilities.

The chase ends when the moving car reaches or goes beyond the position of the other car. The moving car is declared the winner.

Let $S(n)$ be the difference between the winning probabilities of the two cars.

For example, when $n = 2$, the winning probabilities of the two cars are $\frac 9 {11}$ and $\frac 2 {11}$, and thus $S(2) = \frac 7 {11}$.

Let $\displaystyle T(N) = \sum_{n = 2}^N S(n)$.

You are given that $T(10) = 2.38235282$ rounded to 8 digits after the decimal point.

Find $T(10^{14})$, rounded to 8 digits after the decimal point.

Answer: 32.34481054


Consider a wire of length 1 unit between two posts. Every morning $n$ birds land on it randomly with every point on the wire equally likely to host a bird. The interval from each bird to its closest neighbour is then painted.

Define $F(n)$ to be the expected length of the wire that is painted. You are given $F(3) = 0.5$.

Find the average of $F(n)$ where $n$ ranges through all odd prime less than a million. Give your answer rounded to 10 places after the decimal point.

Answer: 0.3889014797


Define $Q(n)$ to be the smallest number that occurs in exactly $n$ Pythagorean triples $(a,b,c)$ where $a \lt b \lt c$.

For example, $15$ is the smallest number occurring in exactly $5$ Pythagorean triples:
$$(9,12,\mathbf{15})\quad (8,\mathbf{15},17)\quad (\mathbf{15},20,25)\quad (\mathbf{15},36,39)\quad (\mathbf{15},112,113)$$
and so $Q(5) = 15$.

You are also given $Q(10)=48$ and $Q(10^3)=8064000$.

Find $\displaystyle \sum_{k=1}^{18} Q(10^k)$. Give your answer modulo $409120391$.

Answer: 397289979


It is a common recreational problem to make a target number using a selection of other numbers. In this problem you will be given six numbers and a target number.

For example, given the six numbers $2$, $3$, $4$, $6$, $7$, $25$, and a target of $211$, one possible solution is:

$$211 = (3+6)\times 25 − (4\times7)\div 2$$
This uses all six numbers. However, it is not necessary to do so. Another solution that does not use the $7$ is:

$$211 = (25−2)\times (6+3) + 4$$

Define the score of a solution to be the sum of the numbers used. In the above example problem, the two given solutions have scores $47$ and $40$ respectively. It turns out that this problem has no solutions with score less than $40$.

When combining numbers, the following rules must be observed:

- Each available number may be used at most once.

- Only the four basic arithmetic operations are permitted: $+$, $-$, $\times$, $\div$.

- All intermediate values must be positive integers, so for example $(3\div 2)$ is never permitted as a subexpression (even if the final answer is an integer).

The attached file number-challenges.txt contains 200 problems, one per line in the format:

211:2,3,4,6,7,25
where the number before the colon is the target and the remaining comma-separated numbers are those available to be used.

Numbering the problems 1, 2, ..., 200, we let $s_n$ be the minimum score of the solution to the $n$th problem. For example, $s_1=40$, as the first problem in the file is the example given above. Note that not all problems have a solution; in such cases we take $s_n=0$.

Find $\displaystyle\sum_{n=1}^{200} 3^n s_n$. Give your answer modulo $1005075251$.

Answer: 148693670


Given any integer $n \gt 1$ a binary factor tree $T(n)$ is defined to be:

- A tree with the single node $n$ when $n$ is prime.

- A binary tree that has root node $n$, left subtree $T(a)$ and right subtree $T(b)$, when $n$ is not prime. Here $a$ and $b$ are positive integers such that $n = ab$, $a\le b$ and $b-a$ is the smallest.

For example $T(20)$:

We define $M(n)$ to be the smallest number that has a factor tree identical in shape to the factor tree for $n!!$, the double factorial of $n$.

For example, consider $9!! = 9\times 7\times 5\times 3\times 1 = 945$. The factor tree for $945$ is shown below together with the factor tree for $72$ which is the smallest number that has a factor tree of the same shape. Hence $M(9) = 72$.

Find $\displaystyle\sum_{n=2}^{31} M(n)$.

Answer: 41768797657018024


Let $\displaystyle S(n)=\sum\limits_{k=0}^{n}\binom{n}{k}k^n$.

You are given, $S(10)=142469423360$.

Find $S(10^{18})$. Submit your answer modulo $83^3 89^3 97^3$.

Answer: 254179446930484376


Let $g(m)$ be the integer defined by the following double sum of products of binomial coefficients:

$$\sum_{j=0}^m\sum_{i = 0}^j (-1)^{j-i}\binom mj \binom ji \binom{j+5+6i}{j+5}.$$

You are given that $g(10) = 127278262644918$.
Its first (most significant) five digits are $12727$.

Find the first ten digits of $g(142857)$ when written in base $7$.

Answer: 5226432553


In this problem $\oplus$ is used to represent the bitwise exclusive or of two numbers.

Starting with blank paper repeatedly do the following:

- Write down the smallest positive integer $a$ which is currently not on the paper;

- Find the smallest positive integer $b$ such that neither $b$ nor $(a \oplus b)$ is currently on the paper. Then write down both $b$ and $(a \oplus b)$.

After the first round $\{1,2,3\}$ will be written on the paper. In the second round $a=4$ and because $(4 \oplus 5)$, $(4 \oplus 6)$ and $(4 \oplus 7)$ are all already written $b$ must be $8$.

After $n$ rounds there will be $3n$ numbers on the paper. Their sum is denoted by $M(n)$.

For example, $M(10) = 642$ and $M(1000) = 5432148$.

Find $M(10^{18})$. Give your answer modulo $1\,000\,000\,007$.

Answer: 552839586


Triangle numbers $T_k$ are integers of the form $\frac{k(k+1)} 2$.

A few triangle numbers happen to be perfect squares like $T_1=1$ and $T_8=36$, but more can be found when considering the product of two triangle numbers. For example, $T_2 \cdot T_{24}=3 \cdot 300=30^2$.

Let $S(n)$ be the sum of $c$ for all integers triples $(a, b, c)$ with $0<c \le n$, $c^2=T_a \cdot T_b$ and $0<a<b$.
For example, $S(100)= \sqrt{T_1 T_8}+\sqrt{T_2 T_{24}}+\sqrt{T_1 T_{49}}+\sqrt{T_3 T_{48}}=6+30+35+84=155$.

You are given $S(10^5)=1479802$ and $S(10^9)=241614948794$.

Find $S(10^{35})$. Give your answer modulo $136101521$.

Answer: 43884302


A sequence is created by starting with a positive integer $n$ and incrementing by $(n+m)$ at the $m^{th}$ step.
If $n=10$, the resulting sequence will be $21,33,46,60,75,91,108,126,\ldots$.

Let $S(n)$ be the set of indices $m$, for which the $m^{th}$ term in the sequence is divisible by $(n+m)$.

For example, $S(10)=\{5,8,20,35,80\}$.

Define $T(n)$ to be the sum of the indices in $S(n)$. For example, $T(10) = 148$ and $T(10^2)=21828$.

Let $\displaystyle U(N)=\sum_{n=3}^{N}T(n)$. You are given, $U(10^2)=612572$.

Find $U(1234567)$.

Answer: 1254404167198752370


A Pythagorean triangle is called supernatural if two of its three sides are consecutive
integers.

Let $S(N)$ be the sum of the perimeters of all distinct supernatural triangles with perimeters less than or equal  to $N$.

For example, $S(100) = 258$ and  $S(10000) = 172004$.

Find $S(10^{10^{10}})$. Give your answer modulo $1234567891$.

Answer: 1050923942


Let $A$ be an affine plane over a radically integral local field $F$ with residual characteristic $p$.

We consider an open oriented line section $U$ of $A$ with normalized Haar measure $m$.

Define $f(m, p)$ as the maximal possible discriminant of the jacobian associated to the orthogonal kernel embedding of $U$ into $A$.

Find $f(20230401, 57)$. Give as your answer the concatenation of the first letters of each bolded word.

Answer: aprilfoolsjoke


Amidakuji (Japanese: 阿弥陀籤) is a method for producing a random permutation of a set of objects.

In the beginning, a number of parallel vertical lines are drawn, one for each object. Then a specified number of horizontal rungs are added, each lower than any previous rungs. Each rung is drawn as a line segment spanning a randomly select pair of adjacent vertical lines.

For example, the following diagram depicts an Amidakuji with three objects ($A$, $B$, $C$) and six rungs:

The coloured lines in the diagram illustrate how to form the permutation. For each object, starting from the top of its vertical line, trace downwards but follow any rung encountered along the way, and record which vertical we end up on. In this example, the resulting permutation happens to be the identity: $A\mapsto A$, $B\mapsto B$, $C\mapsto C$.

Let $a(m, n)$ be the number of different three-object Amidakujis that have $m$ rungs between $A$ and $B$, and $n$ rungs between $B$ and $C$, and whose outcome is the identity permutation. For example, $a(3, 3) = 2$, because the Amidakuji shown above and its mirror image are the only ones with the required property.

You are also given that $a(123, 321) \equiv 172633303 \pmod{1234567891}$.

Find $a(123456789, 987654321)$. Give your answer modulo $1234567891$.

Answer: 428074856


Let $f(N)$ be the smallest positive integer that is not coprime to any positive integer $n \le N$ whose least significant digit is $3$.

For example $f(40)$ equals to $897 = 3 \cdot 13 \cdot 23$ since it is not coprime to any of $3,13,23,33$. By taking the natural logarithm (log to base $e$) we obtain $\ln f(40) = \ln 897 \approx 6.799056$ when rounded to six digits after the decimal point.

You are also given $\ln f(2800) \approx 715.019337$.

Find $f(10^6)$. Enter its natural logarithm rounded to six digits after the decimal point.

Answer: 250591.442792


The sequence $S_n$ is defined by $S_0 = 290797$ and $S_n = S_{n - 1}^2 \bmod 50515093$ for $n > 0$.

There are $N$ bowls indexed $0,1,\dots ,N-1$. Initially there are $S_n$ beans in bowl $n$.

At each step, the smallest index $n$ is found such that bowl $n$ has strictly more beans than bowl $n+1$. Then one bean is moved from bowl $n$ to bowl $n+1$.

Let $B(N)$ be the number of steps needed to sort the bowls into non-descending order.

For example, $B(5) = 0$, $B(6) = 14263289$ and $B(100)=3284417556$.

Find $B(10^7)$.

Answer: 150893234438294408


A partition of $n$ is a set of positive integers for which the sum equals $n$.

The partitions of 5 are:

$\{5\},\{1,4\},\{2,3\},\{1,1,3\},\{1,2,2\},\{1,1,1,2\}$ and $\{1,1,1,1,1\}$.

Further we define the function $D(p)$ as:

$$
\begin{align}
\begin{split}
D(1) &= 1 \\
D(p) &= 1, \text{ for any prime } p \\
D(pq) &= D(p)q + pD(q), \text{ for any positive integers } p,q \gt 1.
\end{split}
\end{align}
$$

Now let $\{a_1, a_2,\ldots,a_k\}$ be a partition of $n$.

We assign to this particular partition the value:
$$P=\prod_{j=1}^{k}D(a_j). $$

$G(n)$ is the sum of $P$ for all partitions of $n$.

We can verify that $G(10) = 164$.

We also define:
$$S(N)=\sum_{n=1}^{N}G(n).$$
You are given $S(10)=396$.

Find $S(5\times 10^4) \mod 999676999$.

Answer: 194396971


The regular star polygon $\{p/q\}$, for coprime integers $p,q$ with $p \gt 2q \gt 0$, is a polygon formed from $p$ edges of equal length and equal internal angles, such that tracing the complete polygon wraps $q$ times around the centre. For example, $\{8/3\}$ is illustrated below:

The edges of a regular star polygon intersect one another, dividing the interior into several regions. Define the alternating shading of a regular star polygon to be a selection of such regions to shade, such that every piece of every edge has a shaded region on one side and an unshaded region on the other, with the exterior of the polygon unshaded. For example, the above image shows the alternating shading (in green) of $\{8/3\}$.

Let $A(p, q)$ be the area of the alternating shading of $\{p/q\}$, assuming that its inradius is $1$. (The inradius of a regular polygon, star or otherwise, is the distance from its centre to the midpoint of any of its edges.) For example, in the diagram above, it can be shown that central shaded octagon has area $8(\sqrt{2}-1)$ and each point's shaded kite has area $2(\sqrt{2}-1)$, giving $A(8,3) = 24(\sqrt{2}-1) \approx 9.9411254970$.

You are also given that $A(130021, 50008)\approx 10.9210371479$, rounded to $10$ digits after the decimal point.

Find $\sum_{n=3}^{34} A(F_{n+1},F_{n-1})$, where $F_j$ is the Fibonacci sequence with $F_1=F_2=1$ (so $A(F_{5+1},F_{5-1}) = A(8,3)$). Give your answer rounded to $10$ digits after the decimal point.

Answer: 381.7860132854


Given $n$ equally spaced points on a circle, we define an $n$-star polygon as an $n$-gon having those $n$ points as vertices. Two $n$-star polygons differing by a rotation/reflection are considered different.

For example, there are twelve $5$-star polygons shown below.

For an $n$-star polygon $S$, let $I(S)$ be the number of its self intersection points.

Let $T(n)$ be the sum of $I(S)$ over all $n$-star polygons $S$.

For the example above $T(5) = 20$ because in total there are $20$ self intersection points.

Some star polygons may have intersection points made from more than two lines. These are only counted once. For example, $S$, shown below is one of the sixty $6$-star polygons. This one has $I(S) = 4$.

You are also given that $T(8) = 14640$.

Find $\displaystyle \sum_{n = 3}^{60}T(n)$. Give your answer modulo $(10^9 + 7)$.

Answer: 885226002


This problem involves an iterative procedure that begins with a circle of $n\ge 3$ integers. At each step every number is simultaneously replaced with the absolute difference of its two neighbours.

For any initial values, the procedure eventually becomes periodic.

Let $S(N)$ be the sum of all possible periods for $3\le n \leq N$. For example, $S(6) = 6$, because the possible periods for $3\le n \leq 6$ are $1, 2, 3$. Specifically, $n=3$ and $n=4$ can each have period $1$ only, while $n=5$ can have period $1$ or $3$, and $n=6$ can have period $1$ or $2$.

You are also given $S(30) = 20381$.

Find $S(100)$.

Answer: 2816775424692


Consider positive integer solutions to

$a^2+b^2+c^2 = 3abc$
For example, $(1,5,13)$ is a solution. We define a 3-Markov number to be any part of a solution, so $1$, $5$ and $13$ are all 3-Markov numbers. Adding distinct 3-Markov numbers $\le 10^3$ would give $2797$.

Now we define a $k$-Markov number to be a positive integer that is part of a solution to:

$\displaystyle \sum_{i=1}^{k}x_i^2=k\prod_{i=1}^{k}x_i,\quad x_i\text{ are positive integers}$

Let $M_k(N)$ be the sum of $k$-Markov numbers $\le N$. Hence $M_3(10^{3})=2797$, also $M_8(10^8) = 131493335$.

Define $\displaystyle S(K,N)=\sum_{k=3}^{K}M_k(N)$. You are given $S(4, 10^2)=229$ and $S(10, 10^8)=2383369980$.

Find $S(10^{18}, 10^{18})$. Give your answer modulo $1\,405\,695\,061$.

Answer: 101805206


Let $D(n)$ be the $n$-th positive integer that has the sum of its digits a prime.

For example, $D(61) = 157$ and $D(10^8) = 403539364$.

Find $D(10^{16})$.

Answer: 45009328011709400


A bracelet is made by connecting at least three numbered beads in a circle. Each bead can only display $1$, $2$, or any number of the form $p^k$ or $2p^k$ for odd prime $p$.

In addition a magic bracelet must satisfy the following two conditions:

-  no two beads display the same number

-  the product of the numbers of any two adjacent beads is of the form $x^2+1$

Define the potency of a magic bracelet to be the sum of numbers on its beads.

The example is a magic bracelet with five beads which has a potency of 155.

Let $F(N)$ be the sum of the potency of each magic bracelet which can be formed using positive integers not exceeding $N$, where rotations and reflections of an arrangement are considered equivalent. You are given $F(20)=258$ and $F(10^2)=538768$.

Find $F(10^6)$.

Answer: 9851175623


Jack has three plates in front of him. The giant has $N$ beans that he distributes to the three plates. All the beans look the same, but one of them is a magic bean. Jack doesn't know which one it is, but the giant knows.

Jack can ask the giant questions of the form: "Does this subset of the beans contain the magic bean?" In each question Jack may choose any subset of beans from a single plate, and the giant will respond truthfully.

If the three plates contain $a$, $b$ and $c$ beans respectively, we let $h(a, b, c)$ be the minimal number of questions Jack needs to ask in order to guarantee he locates the magic bean. For example, $h(1, 2, 3) = 3$ and $h(2, 3, 3) = 4$.

Let $H(N)$ be the sum of $h(a, b, c)$ over all triples of non-negative integers $a$, $b$, $c$ with $1 \leq a + b + c \leq N$.

You are given: $H(6) = 203$ and $H(20) = 7718$.

A repunit, $R_n$, is a number made up with $n$ digits all '1'. For example, $R_3 = 111$ and $H(R_3) = 1634144$.

Find $H(R_{19})$. Give your answer modulo  $1\,000\,000\,007$.

Answer: 381868244


Two players play a game. At the start of the game each player secretly chooses an integer; the first player from $1,...,n$ and the second player from $1,...,m$. Then they take alternate turns, starting with the first player. The player, whose turn it is, displays a set of numbers and the other player tells whether their secret number is in the set or not. The player to correctly guess a set with a single number is the winner and the game ends.

Let $p(m,n)$ be the winning probability of the first player assuming both players play optimally. For example $p(1, n) = 1$ and $p(m, 1) = 1/m$.

You are also given $p(7,5) \approx 0.51428571$.

Find $\displaystyle \sum_{i=0}^{20}\sum_{j=0}^{20} p(7^i, 5^j)$ and give your answer rounded to 8 digits after the decimal point.

Answer: 188.45503259


In a tournament there are $n$ teams and each team plays each other team twice. A team gets two points for a win, one point for a draw and no points for a loss.

With two teams there are three possible outcomes for the total points. $(4,0)$ where a team wins twice, $(3,1)$ where a team wins and draws, and $(2,2)$ where either there are two draws or a team wins one game and loses the other. Here we do not distinguish the teams and so $(3,1)$ and $(1,3)$ are considered identical.

Let $F(n)$ be the total number of possible final outcomes with $n$ teams, so that $F(2) = 3$.

You are also given $F(7) = 32923$.

Find $F(100)$. Give your answer modulo $10^9+7$.

Answer: 936203459


Any positive real number $x$ can be decomposed into integer and fractional parts $\lfloor x \rfloor + \{x\}$, where $\lfloor x \rfloor$ (the floor function) is an integer, and $0\le \{x\} < 1$.

For positive integers $k$ and $n$, define the function
$$\begin{align}
f_k(n) = \sum_{i=1}^{n}\left\{ \frac{i^k}{n} \right\}
\end{align}$$
For example, $f_5(10)=4.5$ and $f_7(1234)=616.5$.

Let
$$\begin{align}
S(N) = \sum_{\substack{k=1 \\ k\text{ odd}}}^{N} \sum_{n=1}^{N}  f_k(n)
\end{align}$$
You are given that $S(10)=100.5$ and $S(10^3)=123687804$.

Find $\lfloor S(33557799775533) \rfloor$. Give your answer modulo 977676779.

Answer: 878255725


Let $n$ be a positive integer and let $E_n$ be the set of $n$-tuples of strictly positive integers.

For $u = (u_1, \cdots, u_n)$ and $v = (v_1, \cdots, v_n)$ two elements of $E_n$, we define:

- the Sum Of Products of $u$ and $v$, denoted by $\langle u, v\rangle$, as the sum $\displaystyle\sum_{i = 1}^n u_i v_i$;

- the Product Of Sums of $u$ and $v$, denoted by $u \star v$, as the product $\displaystyle\prod_{i = 1}^n (u_i + v_i)$.

Let $R_n(M)$ be the sum of $u \star v$ over all ordered pairs $(u, v)$ in $E_n$ such that $\langle u, v\rangle = M$.

For example: $R_1(10) = 36$, $R_2(100) = 1873044$, $R_2(100!) \equiv 446575636 \bmod 10^9 + 7$.

Find $R_6(10000!)$. Give your answer modulo $10^9+7$.

Answer: 726358482


This game has a box of $N$ unfair coins and $N$ fair coins. Fair coins have probability 50% of landing heads while unfair coins have probability 75% of landing heads.

The player begins with a score of 0 which may become negative during play.

At each round the player randomly picks a coin from the box and guesses its type: fair or unfair. Before guessing they may toss the coin any number of times; however, each toss subtracts 1 from their score. The decision to stop tossing and make a guess can be made at any time. After guessing the player's score is increased by 20 if they are right and decreased by 50 if they are wrong. Then the coin type is revealed to the player and the coin is discarded.

After $2N$ rounds the box will be empty and the game is over. Let $S(N)$ be the expected score of the player at the end of the game assuming that they play optimally in order to maximize their expected score.

You are given $S(1) = 20.558591$ rounded to 6 digits after the decimal point.

Find $S(50)$. Give your answer rounded to 6 digits after the decimal point.

Answer: 130.313496


For every positive integer $n$ the Fibonacci sequence modulo
$n$ is periodic. The period depends on the value of $n$.
This period is called the Pisano period for $n$, often shortened to $\pi(n)$.

There are three values of $n$ for which
$\pi(n)$ equals $18$: $19$, $38$ and $76$. The sum of those smaller than $50$ is $57$.

Find the sum of the values of $n$ smaller than $1\,000\,000\,000$ for which $\pi(n)$ equals $120$.

Answer: 44511058204


For every positive integer $n$ the Fibonacci sequence modulo $n$ is periodic. The period depends on the value of $n$.
This period is called the Pisano period for $n$, often shortened to $\pi(n)$.

Define $M(p)$ as the largest integer $n$ such that $\pi(n) = p$, and define $M(p) = 1$ if there is no such $n$.

For example, there are three values of $n$ for which $\pi(n)$ equals $18$: $19, 38, 76$. Therefore $M(18) = 76$.

Let the product function $P(n)$ be: $$P(n)=\prod_{p = 1}^{n}M(p).$$
You are given: $P(10)=264$.

Find $P(1\,000\,000)\bmod 1\,234\,567\,891$.

Answer: 29894398


Given two positive integers $a,b$, Alex and Bianca play a game in $ab$ rounds. They begin with a square piece of paper of side length $1$.

In each round Alex divides the current rectangular piece of paper into $a \times b$ pieces using $a-1$ horizontal cuts and $b-1$ vertical ones. The cuts do not need to be evenly spaced. Moreover, a piece can have zero width/height when a cut coincides with another cut or the edge of the paper. The pieces are then numbered $1, 2, ..., ab$ starting from the left top corner, moving from left to right and starting from the left of the next row when a row is finished.

Then Bianca chooses one of the pieces for the game to continue on. However, Bianca must not choose a piece with a number she has already chosen during the game.

Bianca wants to minimize the area of the final piece of paper while Alex wants to maximize it. Let $S(a,b)$ be the area of the final piece assuming optimal play.

For example, $S(2,2) = 1/36$ and $S(2, 3) = 1/1800 \approx 5.5555555556\mathrm {e}{-4}$.

Find $S(5,8)$. 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.

Answer: 6.8827571976e-57


A standard 52-card deck comprises 13 ranks in four suits. A pair is a set of two cards of the same rank.

Cards are drawn, without replacement, from a well shuffled 52-card deck waiting for consecutive cards that form a pair. For example, the probability of finding a pair in the first two draws is $\frac{1}{17}$.

Cards are drawn until either such a pair is found or the pack is exhausted waiting for one. In the latter case we say that all 52 cards were drawn.

Find the expected number of cards that were drawn. Give your answer rounded to eight places after the decimal point.

Answer: 17.09661501


A graph is made up of vertices and coloured edges.
Between every two distinct vertices there must be exactly one of the following:

- A red directed edge one way, and a blue directed edge the other way

- A green undirected edge

- A brown undirected edge

Such a graph is called beautiful if

- A cycle of edges contains a red edge if and only if it also contains a blue edge

- No triangle of edges is made up of entirely green or entirely brown edges

Below are four distinct examples of beautiful graphs on three vertices:

Below are four examples of graphs that are not beautiful:

Let $G(n)$ be the number of beautiful graphs on the labelled vertices: $1,2,\ldots,n$.
You are given $G(3)=24$, $G(4)=186$ and $G(15)=12472315010483328$.

Find $G(10^7)$. Give your answer modulo $10^9+7$.

Answer: 966332096


Define $G(N) = \sum_S \operatorname{lcm}(S)$ where $S$ ranges through all subsets of $\{1, \dots, N\}$ and $\operatorname{lcm}$ denotes the lowest common multiple. Note that the $\operatorname{lcm}$ of the empty set is $1$.

You are given $G(5) = 528$ and $G(20) = 8463108648960$.

Find $G(800)$. Give your answer modulo $10^9 + 7$.

Answer: 973077199


Odd and Even are playing a game with $N$ cookies.

The game begins with the $N$ cookies divided into one or more piles, not necessarily of the same size. They then make moves in turn, starting with Odd.

Odd's turn: Odd may choose any pile with an odd number of cookies, eat one and divide the remaining (if any) into two equal piles.

Even's turn: Even may choose any pile with an even number of cookies, eat two of them and divide the remaining (if any) into two equal piles.

The player that does not have a valid move loses the game.

Let $C(N)$ be the number of ways that $N$ cookies can be divided so that Even has a winning strategy.

For example, $C(5) = 2$ because there are two winning configurations for Even: a single pile containing all five cookies; three piles containing one, two and two cookies.

You are also given $C(16) = 64$.

Find $C(300)$.

Answer: 1527162658488196


Gary and Sally play a game using gold and silver coins arranged into a number of vertical stacks, alternating turns. On Gary's turn he chooses a gold coin and removes it from the game along with any other coins sitting on top. Sally does the same on her turn by removing a silver coin. The first player unable to make a move loses.

An arrangement is called fair if the person moving first, whether it be Gary or Sally, will lose the game if both play optimally.

Define $F(n)$ to be the number of fair arrangements of $n$ stacks, all of size $2$. Different orderings of the stacks are to be counted separately, so $F(2) = 4$ due to the following four arrangements:

You are also given $F(10) = 63594$.

Find $F(9898)$. Give your answer modulo $989898989$

Answer: 958666903


A unitary divisor of a positive integer $n$ is a divisor $d$ of $n$ such that $\gcd\left(d,\frac{n}{d}\right)=1$.

A bi-unitary divisor of $n$ is a divisor $d$ for which $1$ is the only unitary divisor of $d$ that is also a unitary divisor of $\frac{n}{d}$.

For example, $2$ is a bi-unitary divisor of $8$, because the unitary divisors of $2$ are $\{1,2\}$, and the unitary divisors of $8/2$ are $\{1,4\}$, with $1$ being the only unitary divisor in common.

The bi-unitary divisors of $240$ are $\{1,2,3,5,6,8,10,15,16,24,30,40,48,80,120,240\}$.

Let $P(n)$ be the product of all bi-unitary divisors of $n$. Define $Q_k(N)$ as the number of positive integers $1 \lt n \leq N$ such that $P(n)=n^k$. For example, $Q_2\left(10^2\right)=51$ and $Q_6\left(10^6\right)=6189$.

Find $\sum_{k=2}^{10}Q_k\left(10^{12}\right)$.

Answer: 672623540591


For a positive integer $n$ define $T(n)$ to be the number of strictly larger integers which can be formed by permuting the digits of $n$.

Leading zeros are not allowed and so for $n = 2302$ the total list of permutations would be:

$2023,2032,2203,2230,\mathbf{2302},2320,3022,32 02,3220$

giving $T(2302)=4$.

Further define $S(k)$ to be the sum of $T(n)$ for all $k$-digit numbers $n$. You are given $S(3) = 1701$.

Find $S(12)$.

Answer: 6111397420935766740


Using only a six-sided fair dice and a five-sided fair dice, we would like to emulate an $n$-sided fair dice.

For example, one way to emulate a 28-sided dice is to follow this procedure:

- Roll both dice, obtaining integers $1\le p\le 6$ and $1\le q\le 5$.

- Combine them using $r = 5(p-1) + q$ to obtain an integer $1\le r\le 30$.

- If $r\le 28$, return the value $r$ and stop.

- Otherwise ($r$ being 29 or 30), roll both dice again, obtaining integers $1\le s\le 6$ and $1\le t\le 5$.

- Compute $u = 30(r-29) + 5(s-1) + t$ to obtain an integer $1\le u\le 60$.

- If $u>4$, return the value $((u-5)\bmod 28) + 1$ and stop.

- Otherwise (with $1\le u\le 4$), roll the six-sided dice twice, obtaining integers $1\le v\le 6$ and $1\le w\le 6$.

- Compute $x = 36(u-1) + 6(v-1) + w$ to obtain an integer $1\le x\le 144$.

- If $x>4$, return the value $((x-5)\bmod 28) + 1$ and stop.

- Otherwise (with $1\le x\le 4$), assign $u:=x$ and go back to step 7.

The expected number of dice rolls in following this procedure is 2.142476 (rounded to 6 decimal places). Note that rolling both dice at the same time is still counted as two dice rolls.

There exist other more complex procedures for emulating a 28-sided dice that entail a smaller average number of dice rolls. However, the above procedure has the attractive property that the sequence of dice rolled is predetermined: regardless of the outcome, it follows (D5,D6,D5,D6,D6,D6,D6,...), truncated wherever the process stops. In fact, amongst procedures for $n=28$ with this restriction, this one is optimal in the sense of minimising the expected number of rolls needed.

Different values of $n$ will in general use different predetermined sequences. For example, for $n=8$, the sequence (D5,D5,D5,...) gives an optimal procedure, taking 2.083333... dice rolls on average.

Define $R(n)$ to be the expected number of dice rolls for an optimal procedure for emulating an $n$-sided dice using only a five-sided and a six-sided dice, considering only those procedures where the sequence of dice rolled is predetermined. So, $R(8) \approx 2.083333$ and $R(28) \approx 2.142476$.

Let $S(n) = \displaystyle\sum_{k=2}^n R(k)$. You are given that $S(30) \approx 56.054622$.

Find $S(1000)$. Give your answer rounded to 6 decimal places.

Answer: 3862.871397


Let $C(n)$ be the number of squarefree integers of the form $x^2 + 1$ such that $1 \le x \le n$.

For example, $C(10) = 9$ and $C(1000) = 895$.

Find $C(123567101113)$.

Answer: 110572936177


A triplicate number is a positive integer such that, after repeatedly removing three consecutive identical digits from it, all its digits can be removed.

For example, the integer $122555211$ is a triplicate number:
$$122{\color{red}555}211 \rightarrow 1{\color{red}222}11\rightarrow{\color{red}111}\rightarrow.$$
On the other hand, neither $663633$ nor $9990$ are triplicate numbers.

Let $T(n)$ be how many triplicate numbers are less than $10^n$.

For example, $T(6) = 261$ and $T(30) = 5576195181577716$.

Find $T(10^4)$. Give your answer modulo $998244353$.

Answer: 761181918


A small child has a “number caterpillar” consisting of $N$ jigsaw pieces, each with one number on it, which, when connected together in a line, reveal the numbers $1$ to $N$ in order.

Every night, the child's father has to pick up the pieces of the caterpillar that have been scattered across the play room. He picks up the pieces at random and places them in the correct order.

As the caterpillar is built up in this way, it forms distinct segments that gradually merge together.

Any time the father places a new piece in its correct position, a segment of length $k$ is formed and he writes down the $k$th hexagonal number $k\cdot(2k-1)$. Once all pieces have been placed and the full caterpillar constructed he calculates the product of all the numbers written down. Interestingly, the expected value of this product is always an integer. For example if $N=4$ then the expected value is $994$.

Find the expected value of the product for a caterpillar of $N=100$ pieces.
Give your answer modulo $987654319$.

Answer: 492401720


There are $5$ ways to tile a regular dodecagon of side $1$ with regular polygons of side $1$.

Let $T(n)$ be the number of ways to tile a regular dodecagon of side $n$ with regular polygons of side $1$. Then $T(1) = 5$. You are also given $T(2) = 48$.

Find $T(10)$. Give your answer modulo $10^9+7$.

Answer: 870557257


There is a method that is used by Bell ringers to generate all variations of the order that bells are rung.

The same method can be used to create all permutations of a set of letters. Consider the letters to be permuted initially in order from smallest to largest. At each step swap the largest letter with the letter on its left or right whichever generates a permutation that has not yet been seen. If neither gives a new permutation then try the next largest letter and so on. This procedure continues until all permutations have been generated.

For example, $3$ swaps are required to reach the permutation CBA when starting with ABC.

The swaps are ABC $\to$ ACB $\to$ CAB $\to$ CBA.

Also $59$ swaps are required to reach BELFRY when starting with these letters in alphabetical order.

Find the number of swaps that are required to reach NOWPICKBELFRYMATHS when starting with these letters in alphabetical order.

Answer: 3832914911887589


A prime is drawn uniformly from all primes not exceeding $N$. The prime is written in binary notation, and a player tries to guess it bit-by-bit starting at the least significant bit. The player scores one point for each bit they guess correctly. Immediately after each guess, the player is informed whether their guess was correct, and also whether it was the last bit in the number - in which case the game is over.

Let $E(N)$ be the expected number of points assuming that the player always guesses to maximize their score. For example, $E(10)=2$, achievable by always guessing "1". You are also given $E(30)=2.9$.

Find $E(10^8)$. Give your answer rounded to eight digits after the decimal point.

Answer: 14.97696693


Two players play a game with a single pile of stones of initial size $n$. They take stones from the pile in turn, according to the following rules which depend on a fixed real number $r > 0$:

-
In the first turn, the first player may take $k$ stones with $1 \le k \lt n$.

-
If a player takes $m$ stones in a turn, then in the next turn the opponent may take $k$ stones with $1 \le k \le \lfloor r \cdot m \rfloor$.

Whoever cannot make a legal move loses the game.

Let $L(r)$ be the set of initial pile sizes $n$ for which the second player has a winning strategy. For example, $L(0.5) = \{1\}$, $L(1) = \{1, 2, 4, 8, 16, \dots\}$, $L(2) = \{1, 2, 3, 5, 8, \dots\}$.

A real number $q \gt 0$ is a transition value if $L(s)$ is different from $L(t)$ for all $s < q < t$.

Let $T(i)$ be the $i$-th transition value. For example, $T(1) = 1$, $T(2) = 2$, $T(22) \approx 6.3043478261$.

Find $T(123456)$ and give your answer rounded to $10$ digits after the decimal point.

Answer: 229.9129353234


Let $f$ be a function from a finite set $S$ to itself. A drifting subset for $f$ is a subset $A$ of $S$ such that the number of elements in the union $A \cup f(A)$ is equal to twice the number of elements of $A$.

We write $D(f)$ for the maximal number of elements among all drifting subsets for $f$.

For a positive integer $n$, define $f_n$ as the function from $\{0, 1, \dots, n - 1\}$ to itself sending $x$ to $x^3 + x + 1 \bmod n$.

You are given $D(f_5) = 1$ and $D(f_{10}) = 3$.

Find $\displaystyle\sum_{i = 1}^{100} D(f_{10^5 + i})$.

Answer: 2848790


A sequence of rooted trees $T_n$ is constructed such that $T_n$ has $n$ nodes numbered $1$ to $n$.

The sequence starts at $T_1$, a tree with a single node as a root with the number $1$.

For $n > 1$, $T_n$ is constructed from $T_{n-1}$ using the following procedure:

- Trace a path from the root of $T_{n-1}$ to a leaf by following the largest-numbered child at each node.

- Remove all edges along the traced path, disconnecting all nodes along it from their parents.

- Connect all orphaned nodes directly to a new node numbered $n$, which becomes the root of $T_n$.

For example, the following figure shows $T_6$ and $T_7$. The path traced through $T_6$ during the construction of $T_7$ is coloured red.

Let $f(n, k)$ be the sum of the node numbers along the path connecting the root of $T_n$ to the node $k$, including the root and the node $k$. For example, $f(6, 1) = 6 + 5 + 1 = 12$ and $f(10, 3) = 29$.

Find $f(10^{17}, 9^{17})$.

Answer: 2903144925319290239


Let $W(p,q,r)$ be the number of words that can be formed using the letter A $p$ times, the letter B $q$ times and the letter C $r$ times with the condition that every A is separated from every B by at least two Cs. For example, CACACCBB is a valid word for $W(2,2,4)$ but ACBCACBC is not.

You are given $W(2,2,4)=32$ and $W(4,4,44)=13908607644$.

Find $W(10^6,10^7,10^8)$. Give your answer modulo $1\,000\,000\,007$.

Answer: 735131856


Let $p(t)$ denote the $(t+1)$th prime number. So that $p(0) = 2$, $p(1) = 3$, etc.

We define the prime score of a list of nonnegative integers $[a_1, \dots, a_n]$ as the sum $\sum_{i = 1}^n p(a_i)$.

Let $M(k, n)$ be the maximal prime score among all lists $[a_1, \dots, a_n]$ such that:

-  $0 \leq a_i < k$ for each $i$;

-  the sum $\sum_{i = 1}^n a_i$ is a multiple of $k$.

For example, $M(2, 5) = 14$ as $[0, 1, 1, 1, 1]$ attains a maximal prime score of $14$.

Find $M(7000, p(7000))$.

Answer: 4992775389


For a positive integer $n$ we define $q(n)$ to be the number of solutions to:

$$a_1^2+a_2^2+a_3^2+a_4^2 \equiv b_1^2+b_2^2+b_3^2+b_4^2 \pmod n$$
where $0 \leq a_i, b_i \lt n$. For example, $q(4)= 18432$.

Define $\displaystyle Q(n)=\sum_{i=1}^{n}q(i)$. You are given $Q(10)=18573381$.

Find $Q(12345678)$. Give your answer modulo $1001961001$.

Answer: 79645946


Starting with three numbers $a, b, c$, at each step do one of the three operations:

- change $a$ to $2(b + c) - a$;

- change $b$ to $2(c + a) - b$;

- change $c$ to $2(a + b) - c$;

Define $f(a, b, c)$ to be the minimum number of steps required for one number to become zero. If this is not possible then $f(a, b, c)=0$.

For example, $f(6,10,35)=3$:
$$(6,10,35) \to (6,10,-3) \to (8,10,-3) \to (8,0,-3).$$
However, $f(6,10,36)=0$ as no series of operations leads to a zero number.

Also define $F(a, b)=\sum_{c=1}^\infty f(a,b,c)$.
You are given $F(6,10)=17$ and $F(36,100)=179$.

Find $\displaystyle\sum_{k=1}^{18}F(6^k,10^k)$.

Answer: 457019806569269


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) = 5
\end{align}$$

For example, $(a, b) = (3, 6)$ is a solution.

Let $X(N)$ be the XOR of the $b$ values for all solutions to this equation satisfying $0 \le a \le b \le N$.
You are given $X(10)=5$.

Find $X(10^{18})$.

Answer: 336785000760344621


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) = k.
\end{align}$$

For example, $(a, b) = (3, 6)$ is a solution to this equation for $k=5$.

Let $G(N,m)$ be the number of solutions to those equations with $k \le m$ and $0 \le a \le b \le N$.

You are given $G(1000,100)=398$.

Find $G(10^{17},1\,000\,000).$

Answer: 23707109


A touch-screen device can be unlocked with a "password" consisting of a sequence of two or more distinct spots that the user selects from a rectangular grid of spots on the screen. The user enters their sequence by touching the first spot, then tracing a straight line segment to the next spot, and so on until the end of the sequence. The user's finger remains in contact with the screen throughout, and may only move in straight line segments from spot to spot.

If the finger traces a straight line that passes over an intermediate spot, then that is treated as two line segments with the intermediate spot included in the password sequence. For example, on a $3\times 3$ grid labelled with digits $1$ to $9$ (shown below), tracing $1-9$ is interpreted as $1-5-9$.

Once a spot has been selected it disappears from the screen. Thereafter, the spot may not be used as an endpoint of future line segments, and it is ignored by any future line segments which happen to pass through it. For example, tracing $1-9-3-7$ (which crosses the $5$ spot twice) will give the password $1-5-9-6-3-7$.

There are $389488$ different passwords that can be formed on a $3 \times 3$ grid.

Find the number of different passwords that can be formed on a $4 \times 4$ grid.

Answer: 4350069824940


$(x,y)$ is called a nested radical pair if $x$ and $y$ are non-zero integers such that $\dfrac{x}{y}$ is not a cube of a rational number, and there exist integers $a$, $b$ and $c$ such that:

$$\sqrt{\sqrt[3]{x}+\sqrt[3]{y}}=\sqrt[3]{a}+\sqrt[3]{b}+\sqrt[3]{c}$$
For example, both $(-4,125)$ and $(5,5324)$ are nested radical pairs:

$$
\begin{align*}
\begin{split}
\sqrt{\sqrt[3]{-4}+\sqrt[3]{125}}	&= \sqrt[3]{-1}+\sqrt[3]{2}+\sqrt[3]{4}\\
\sqrt{\sqrt[3]{5}+\sqrt[3]{5324}}	&= \sqrt[3]{-2}+\sqrt[3]{20}+\sqrt[3]{25}\\
\end{split}
\end{align*}
$$

Let $H(N)$ be the sum of $|x|+|y|$ for all the nested radical pairs $(x, y)$ where $|x| \leq |y|\leq N$.

For example, $H(10^3)=2535$.

Find $H(10^{15})$. Give your answer modulo $1031^3+2$.

Answer: 522095328


For a positive integer $n$ create a graph using its divisors as vertices. An edge is drawn between two vertices $a \lt b$ if their quotient $b/a$ is prime. The graph can be arranged into levels where vertex $n$ is at level $0$ and vertices that are a distance $k$ from $n$ are on level $k$. Define $g(n)$ to be the maximum number of vertices in a single level.

The example above shows that $g(45) = 2$. You are also given $g(5040) = 12$.

Find the smallest number, $n$, such that $g(n) \ge 10^4$.

Answer: 205702861096933200


Dr. One and Dr. Zero are playing the following partisan game.

The game begins with one $1$, two $2$'s, three $3$'s, ..., $n$ $n$'s. Starting with Dr. One, they make moves in turn.

Dr. One chooses a number and changes it by removing a $1$ from its binary expansion.

Dr. Zero chooses a number and changes it by removing a $0$ from its binary expansion.

The player that is unable to move loses.

Note that leading zeros are not allowed in any binary expansion; in particular nobody can make a move on the number $0$.

They soon realize that Dr. Zero can never win the game. In order to make it more interesting, Dr. Zero is allowed to "skip the turn" several times, i.e. passing the turn back to Dr. One without making a move.

For example, when $n = 2$, Dr. Zero can win the game if allowed to skip $2$ turns. A sample game:
$$
[1, 2, 2]\xrightarrow{\textrm{Dr. One}}[1, 0, 2]\xrightarrow{\textrm{Dr. Zero}}[1, 0, 1]\xrightarrow{\textrm{Dr. One}}[1, 0, 0]\xrightarrow[\textrm{skip}]{\textrm{Dr. Zero}}
[1, 0, 0]\xrightarrow{\textrm{Dr. One}}[0, 0, 0]\xrightarrow[\textrm{skip}]{\textrm{Dr. Zero}}[0, 0, 0].
$$
Let $S(n)$ be the minimal number of skips needed so that Dr. Zero has a winning strategy.

For example, $S(2) = 2$, $S(5) = 17$, $S(10) = 64$.

Find $S(10^5)$.

Answer: 15800662276


In this problem we consider triangles drawn on a hexagonal lattice, where each lattice point in the plane has six neighbouring points equally spaced around it, all distance $1$ away.

We call a triangle remarkable if

- All three vertices and its incentre lie on lattice points

- At least one of its angles is $60^\circ$

Above are four examples of remarkable triangles, with $60^\circ$ angles illustrated in red. Triangles A and B have inradius $1$; C has inradius $\sqrt{3}$; D has inradius $2$.

Define $T(r)$ to be the number of remarkable triangles with inradius $\le r$. Rotations and reflections, such as triangles A and B above, are counted separately; however direct translations are not. That is, the same triangle drawn in different positions of the lattice is only counted once.

You are given $T(0.5)=2$, $T(2)=44$, and $T(10)=1302$.

Find $T(10^6)$.

Answer: 14854003484704


Starting from a positive integer $n$, at each step we subtract from $n$ the largest perfect cube not exceeding $n$, until $n$ becomes $0$.

For example, with $n = 100$ the procedure ends in $4$ steps:
$$100 \xrightarrow{-4^3} 36 \xrightarrow{-3^3} 9 \xrightarrow{-2^3} 1 \xrightarrow{-1^3} 0.$$
Let $D(n)$ denote the number of steps of the procedure. Thus $D(100) = 4$.

Let $S(N)$ denote the sum of $D(n)$ for all positive integers $n$ strictly less than $N$.

For example, $S(100) = 512$.

Find $S(10^{17})$.

Answer: 1105985795684653500


For a positive integer $d$, let $f(d)$ be the number created by sorting the digits of $d$ in ascending order, removing any zeros. For example, $f(3403) = 334$.

Let $S(n)$ be the sum of $f(d)$ for all positive integers $d$ of $n$ digits or less. You are given $S(1) = 45$ and $S(5) = 1543545675$.

Find $S(18)$. Give your answer modulo $1123455689$.

Answer: 827850196


A permutation of $\{2,3,\ldots,n\}$ is a rearrangement of these numbers. A coprime permutation is a rearrangement such that all pairs of adjacent numbers are coprime.

Let $P(n)$ be the number of coprime permutations of $\{2,3,\ldots,n\}$.

For example, $P(4)=2$ as there are two coprime permutations, $(2,3,4)$ and $(4,3,2)$. You are also given $P(10)=576$.

Find $P(34)$ and give your answer modulo $83\,456\,729$.

Answer: 5570163


Consider the problem of determining a secret number from a set $\{1, ..., N\}$ by repeatedly choosing a number $y$ and asking "Is the secret number greater than $y$?".

If $N=1$ then no questions need to be asked. If $N=2$ then only one question needs to be asked. If $N=64$ then six questions need to be asked. However, in the latter case if the secret number is $1$ then six questions still need to be asked. We want to restrict the number of questions asked for small values.

Let $Q(N, d)$ be the least number of questions needed for a strategy that can find any secret number from the set $\{1, ..., N\}$ where no more than $x + d$ questions are needed to find the secret value $x$.

It can be proved that $Q(N, 0) = N - 1$. You are also given $Q(7, 1) = 3$ and $Q(777, 2) = 10$.

Find $\displaystyle \sum_{d=0}^7 \sum_{N=1}^{7^{10}} Q(N, d)$.

Answer: 39896187138661622


Two players play a game with a number of piles of stones, alternating turns. Each turn a player can choose to remove 1, 2, 4, or 9 stones from a single pile; or alternatively they can choose to split a pile containing two or more stones into two non-empty piles. The winner is the player who removes the last stone.

A collection of piles is called a losing position if the player to move cannot force a win with optimal play. Define $S(N, m)$ to be the number of distinct losing positions arising from $m$ piles of stones where each pile contains from $1$ to $N$ stones. Two positions are considered equivalent if they consist of the same pile sizes. That is, the order of the piles does not matter.

You are given $S(12,4)=204$ and $S(124,9)=2259208528408$.

Find $S(12491249,1249)$. Give your answer modulo $912491249$.

Answer: 227429102


Recall the blancmange function from Problem 226: $T(x) = \sum\limits_{n = 0}^\infty\dfrac{s(2^nx)}{2^n}$, where $s(x)$ is the distance from $x$ to the nearest integer.

For positive integers $k, t, r$, we write $$F(k, t, r) = (2^{2k} - 1)T\left(\frac{(2^t + 1)^r}{2^k + 1}\right).$$ It can be shown that $F(k, t, r)$ is always an integer.

For example, $F(3, 1, 1) = 42$, $F(13, 3, 3) = 23093880$ and $F(103, 13, 6) \equiv 878922518\pmod {1\,000\,062\,031}$.

Find $F(10^{18} + 31, 10^{14} + 31, 62)$. Give your answer modulo $1\,000\,062\,031$.

Answer: 424315113


Let $p(n)$ be the number of ways to write $n$ as the sum of powers of two, ignoring order.

For example, $p(7) = 6$, the partitions being
$$
\begin{align}
7 &= 1+1+1+1+1+1+1 \\
&=1+1+1+1+1+2 \\
&=1+1+1+2+2 \\
&=1+1+1+4 \\
&=1+2+2+2 \\
&=1+2+4
\end{align}
$$
You are also given $p(7^7) \equiv 144548435 \pmod {10^9+7}$.

Find $p(7^{777})$. Give your answer modulo $10^9 + 7$.

Answer: 820442179


A round clock only has three hands: hour, minute, second. All hands look identical and move continuously. Moreover, there is no number or reference mark so that the "upright position" is unknown. The clock functions the same as a normal 12-hour analogue clock.

Despite the inconvenient design, for most time it is possible to tell the correct time (within a 12-hour cycle) from the clock, just by measuring accurately the angles between the hands. For example, if all three hands coincide, then the time must be 12:00:00.

Nevertheless, there are several moments where the clock shows an ambiguous reading. For example, the following moment could be either 1:30:00 or 7:30:00 (with the clock rotated $180^\circ$). Thus both 1:30:00 and 7:30:00 are ambiguous moments.

Note that even if two hands perfectly coincide, we can still see them as two distinct hands in the same position. Thus for example 3:00:00 and 9:00:00 are not ambiguous moments.

How many ambiguous moments are there within a 12-hour cycle?

Answer: 1541414


Consider a circle where $2n$ distinct points have been marked on its circumference.

A cutting $C$ consists of connecting the $2n$ points with $n$ line segments, so that no two line segments intersect, including on their end points. The $n$ line segments then cut the circle into $n + 1$ pieces.
Each piece is painted either black or white, so that adjacent pieces are opposite colours.
Let $d(C)$ be the absolute difference between the numbers of black and white pieces under the cutting $C$.

Let $D(n)$ be the sum of $d(C)$ over all different cuttings $C$.
For example, there are five different cuttings with $n = 3$.

The upper three cuttings all have $d = 0$ because there are two black and two white pieces; the lower two cuttings both have $d = 2$ because there are three black and one white pieces.
Therefore $D(3) = 0 + 0 + 0 + 2 + 2 = 4$.
You are also given $D(100) \equiv 1172122931\pmod{1234567891}$.

Find $\displaystyle \sum_{n=1}^{10^7} D(n)$. Give your answer modulo $1234567891$.

Answer: 469137427


Define $M(n)$ to be the minimum number of matchsticks needed to represent the number $n$.

A number can be represented in digit form or as an expression involving addition and/or multiplication. Also order of operations must be followed, that is multiplication binding tighter than addition. Any other symbols or operations, such as brackets, subtraction, division or exponentiation, are not allowed.

The valid digits and symbols are shown below:

For example, $28$ needs $12$ matchsticks to represent it in digit form but representing it as $4\times 7$ would only need $9$ matchsticks and as there is no way using fewer matchsticks $M(28) = 9$.

Define $\displaystyle T(N) = \sum_{n=1}^N M(n)$. You are given $T(100) = 916$.

Find $T(10^6)$.

Answer: 26688208


Consider a unit circlecircle with radius 1 $C_0$ on the plane that does not enclose the origin. For $k\ge 1$, a circle $C_k$ is created by scaling and rotating $C_{k - 1}$ with respect to the origin. That is, both the radius and the distance to the origin are scaled by the same factor, and the centre of rotation is the origin. The scaling factor is positive and strictly less than one. Both it and the rotation angle remain constant for each $k$.

It is given that $C_0$ is externally tangent to $C_1$, $C_7$ and $C_8$, as shown in the diagram below, and no two circles overlap.

Find the total area of all the circular trianglesA circular triangle is a triangle with circular arc edges in the diagram, i.e. the area painted green above.

Give your answer rounded to $10$ places after the decimal point.

Answer: 0.7718678168


Gary and Sally play a game using gold and silver coins arranged into a number of vertical stacks, alternating turns. On Gary's turn he chooses a gold coin and removes it from the game along with any other coins sitting on top. Sally does the same on her turn by removing a silver coin. The first player unable to make a move loses.

An arrangement is called fair if the person moving first, whether it be Gary or Sally, will lose the game if both play optimally.

An arrangement is called balanced if the number of gold and silver coins are equal.

Define $G(m)$ to be the number of fair and balanced arrangements consisting of three non-empty stacks, each not exceeding $m$ in size. Different orderings of the stacks are to be counted separately, so $G(2)=6$ due to the following six arrangements:

You are also given $G(5)=348$ and $G(20)=125825982708$.

Find $G(9898)$ giving your answer modulo $989898989$.

Answer: 670785433


A contiguous range of positive integers is called a divisible range if all the integers in the range can be arranged in a row such that the $n$-th term is a multiple of $n$.

For example, the range $[6..9]$ is a divisible range because we can arrange the numbers as $7,6,9,8$.

In fact, it is the $4$th divisible range of length $4$, the first three being $[1..4], [2..5], [3..6]$.

Find the $36$th divisible range of length $36$.

Give as answer the smallest number in the range.

Answer: 274229635640


Let $G(n)$ denote the largest possible area of an $n$-gona polygon with $n$ sides contained in the region $\{(x, y) \in \Bbb R^2: x^4 \leq y \leq 1\}$.

For example, $G(3) = 1$ and $G(5)\approx 1.477309771$.

Find $G(101)$ rounded to nine digits after the decimal point.

Answer: 1.599827123


Claire Voyant is a teacher playing a game with a class of students.
A fair coin is tossed on the table. All the students can see the outcome of the toss, but Claire cannot.
Each student then tells Claire whether the outcome is head or tail. The students may lie, but Claire knows the probability that each individual student lies. Moreover, the students lie independently.
After that, Claire attempts to guess the outcome using an optimal strategy.

For example, for a class of four students with lying probabilities $20\%,40\%,60\%,80\%$, Claire guesses correctly with probability 0.832.

Find the probability that Claire guesses correctly for a class of 51 students each lying with a probability of $25\%, 26\%, \dots, 75\%$
respectively.

Give your answer rounded to 10 digits after the decimal point.

Answer: 0.9861343531


Two players play a game with two piles of stones. The players alternately take stones from one or both piles, subject to:

- the total number of stones taken is equal to the size of the smallest pile before the move;

- the move cannot take all the stones from a pile.

The player that is unable to move loses.

For example, if the piles are of sizes 3 and 5 then there are three possible moves.
$$(3,5) \xrightarrow{(2,1)} (1,4)\qquad\qquad (3,5) \xrightarrow{(1,2)} (2,3)\qquad\qquad (3,5) \xrightarrow{(0,3)} (3,2)$$

Let $L(n)$ be the number of ordered pairs $(a,b)$ with $1 \leq a,b \leq n$ such that the initial game position with piles of sizes $a$ and $b$ is losing for the first player assuming optimal play.

You are given $L(7) = 21$ and $L(7^2) = 221$.

Find $L(7^{17})$.

Answer: 10784223938983273


Two players play a game with at least two piles of stones. The players alternately take stones from one or more piles, subject to:

- the total number of stones taken is equal to the size of the smallest pile before the move;

- the move cannot take all the stones from a pile.

The player that is unable to move loses.

For example, if the piles are of sizes 2, 2 and 4 then there are four possible moves.
$$ (2,2,4)\xrightarrow{(1,1,0)}(1,1,4)\quad (2,2,4)\xrightarrow{(1,0,1)}(1,2,3)\quad
(2,2,4)\xrightarrow{(0,1,1)}(2,1,3)\quad (2,2,4)\xrightarrow{(0,0,2)}(2,2,2)$$

Let $t(n)$ be the smallest nonnegative integer $k$ such that the position with $n$ piles of $n$ stones and a single pile of $n+k$ stones is losing for the first player assuming optimal play.  For example, $t(1) = t(2) = 0$ and $t(3) = 2$.

Define $\displaystyle S(N) = \sum_{n=1}^{2^N} t(n)$.  You are given $S(10) = 361522$.

Find $S(10^4)$. Give your answer modulo $900497239$.

Answer: 646900900


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.

Answer: 2.364497769


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)$.

Answer: 343557869


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)$.

Answer: 128553191


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})$.

Answer: 880652522278760


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)$.

Answer: 70228218


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.

Answer: 0.0195868911


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$.

Answer: 196808901


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$.

Answer: 451822602