The $n$th harmonic number $H_n$ is defined as the sum of the multiplicative inverses of the first $n$ positive integers, and can be written as a reduced fraction $a_n/b_n$.

$H_n = \displaystyle \sum_{k=1}^n \frac 1 k = \frac {a_n} {b_n}$, with $\gcd(a_n, b_n)=1$.

Let $M(p)$ be the largest value of $n$ such that $b_n$ is not divisible by $p$.

For example, $M(3) = 68$ because $H_{68} = \frac {a_{68}} {b_{68}} = \frac {14094018321907827923954201611} {2933773379069966367528193600}$, $b_{68}=2933773379069966367528193600$ is not divisible by $3$, but all larger harmonic numbers have denominators divisible by $3$.

You are given $M(7) = 719102$.

Find $M(137)$.

Answer: 4580726482872451


Let $S(k)$ be the sum of three or more distinct positive integers having the following properties:

- No value exceeds $k$.

- The values form a geometric progression.

- The sum is maximal.

$S(4) = 4 + 2 + 1 = 7$

$S(10) = 9 + 6 + 4 = 19$

$S(12) = 12 + 6 + 3 = 21$

$S(1000) = 1000 + 900 + 810 + 729 = 3439$

Let $T(n) = \sum_{k=4}^n (-1)^k S(k)$.

$T(1000) = 2268$

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

Answer: 697586734240314852


Define function $P(n, k) = 1$ if $n$ can be written as the sum of $k$ prime numbers (with repetitions allowed), and $P(n, k) = 0$ otherwise.

For example, $P(10,2) = 1$ because $10$ can be written as either $3 + 7$ or $5 + 5$, but $P(11,2) = 0$ because no two primes can sum to $11$.

Let $S(n)$ be the sum of all $P(i,k)$ over $1 \le i,k \le n$.

For example, $S(10) = 20$, $S(100) = 2402$, and $S(1000) = 248838$.

Let $F(k)$ be the $k$th Fibonacci number (with $F(0) = 0$ and $F(1) = 1$).

Find the sum of all $S(F(k))$ over $3 \le k \le 44$.

Answer: 199007746081234640


Let $F(r, c, n)$ be the number of ways to colour a rectangular grid with $r$ rows and $c$ columns using at most $n$ colours such that no two adjacent cells share the same colour. Cells that are diagonal to each other are not considered adjacent.

For example, $F(2,2,3) = 18$, $F(2,2,20) = 130340$, and $F(3,4,6) = 102923670$.

Let $S(r, c, n) = \sum_{k=1}^{n} F(r, c, k)$.

For example, $S(4,4,15) \bmod 10^9+7 = 325951319$.

Find $S(9,10,1112131415) \bmod 10^9+7$.

Answer: 640432376


The sum of the $k$th powers of the first $n$ positive integers can be expressed as a polynomial of degree $k+1$ with rational coefficients, the Faulhaber's Formulas:

$1^k + 2^k + ... + n^k = \sum_{i=1}^n i^k = \sum_{i=1}^{k+1} a_{i} n^i = a_{1} n + a_{2} n^2 + ... + a_{k} n^k + a_{k+1} n^{k + 1}$,

where $a_i$'s are rational coefficients that can be written as reduced fractions $p_i/q_i$ (if $a_i = 0$, we shall consider $q_i = 1$).

For example, $1^4 + 2^4 + ... + n^4 = -\frac 1 {30} n + \frac 1 3 n^3 + \frac 1 2 n^4 + \frac 1 5 n^5.$

Define $D(k)$ as the value of $q_1$ for the sum of $k$th powers (i.e. the denominator of the reduced fraction $a_1$).

Define $F(m)$ as the $m$th value of $k \ge 1$ for which $D(k) = 20010$.

You are given $D(4) = 30$ (since $a_1 = -1/30$), $D(308) = 20010$, $F(1) = 308$, $F(10) = 96404$.

Find $F(10^5)$.

Answer: 921107572


Answer: 215656873


Assuming that two points are chosen randomly (with uniform distribution) within a rectangle, it is possible to determine the expected value of the distance between these two points.

For example, the expected distance between two random points in a unit square is about $0.521405$, while the expected distance between two random points in a rectangle with side lengths $2$ and $3$ is about $1.317067$.

Now we define a hollow square lamina of size $n$ to be an integer sized square with side length $n \ge 3$ consisting of $n^2$ unit squares from which a rectangle consisting of $x \times y$ unit squares ($1 \le x,y \le n - 2$) within the original square has been removed.

For $n = 3$ there exists only one hollow square lamina:

For $n = 4$ you can find $9$ distinct hollow square laminae, allowing shapes to reappear in rotated or mirrored form:

Let $S(n)$ be the sum of the expected distance between two points chosen randomly within each of the possible hollow square laminae of size $n$. The two points have to lie within the area left after removing the inner rectangle, i.e. the gray-colored areas in the illustrations above.

For example, $S(3) = 1.6514$ and $S(4) = 19.6564$, rounded to four digits after the decimal point.

Find $S(40)$ rounded to four digits after the decimal point.

Answer: 11730879.0023


A gozinta chain for $n$ is a sequence $\{1,a,b,\dots,n\}$ where each element properly divides the next.

There are eight gozinta chains for $12$:

$\{1,12\}$, $\{1,2,12\}$, $\{1,2,4,12\}$, $\{1,2,6,12\}$, $\{1,3,12\}$, $\{1,3,6,12\}$, $\{1,4,12\}$ and $\{1,6,12\}$.

Let $g(n)$ be the number of gozinta chains for $n$, so $g(12)=8$.

$g(48)=48$ and $g(120)=132$.

Find the sum of the numbers $n$  not exceeding $10^{16}$ for which $g(n)=n$.

Answer: 12144044603581281


The smallest number $m$ such that $10$ divides $m!$ is $m=5$.

The smallest number $m$ such that $25$ divides $m!$ is $m=10$.

Let $s(n)$ be the smallest number $m$ such that $n$ divides $m!$.

So $s(10)=5$ and $s(25)=10$.

Let $S(n)$ be $\sum s(i)$ for $2 \le i \le n$.

$S(100)=2012$.

Find $S(10^8)$.

Answer: 476001479068717


Two players are playing a game, alternating turns. There are $k$ piles of stones.
On each turn, a player has to choose a pile and replace it with two piles of stones under the following two conditions:

-  Both new piles must have a number of stones more than one and less than the number of stones of the original pile.

-  The number of stones of each of the new piles must be a divisor of the number of stones of the original pile.

The first player unable to make a valid move loses.

Let $f(n,k)$ be the number of winning positions for the first player, assuming perfect play, when the game is played with $k$ piles each having between $2$ and $n$ stones (inclusively).
$f(10,5)=40085$.

Find $f(10^7,10^{12})$.
Give your answer modulo $987654321$.

Answer: 328104836


Let $a_0, a_1, \dots$ be an integer sequence defined by:

- $a_0 = 1$;

- for $n \ge 1$, $a_n$ is the sum of the digits of all preceding terms.

The sequence starts with $1, 1, 2, 4, 8, 16, 23, 28, 38, 49, \dots$

You are given $a_{10^6} = 31054319$.

Find $a_{10^{15}}$.

Answer: 73597483551591773


Let $A_n$ be the smallest positive integer satisfying $A_n \bmod p_i = i$ for all $1 \le i \le n$, where $p_i$ is the
$i$-th prime.

For example $A_2 = 5$, since this is the smallest positive solution of the system of equations

-  $A_2 \bmod 2 = 1$

-  $A_2 \bmod 3 = 2$

The system of equations for $A_3$ adds another constraint. That is, $A_3$ is the smallest positive solution of

-  $A_3 \bmod 2 = 1$

-  $A_3 \bmod 3 = 2$

-  $A_3 \bmod 5 = 3$

and hence $A_3 = 23$. Similarly, one gets $A_4 = 53$ and $A_5 = 1523$.

Let $S(n)$ be the sum of all primes up to $n$ that divide at least one element in the sequence $A$.

For example, $S(50) = 69 = 5 + 23 + 41$, since $5$ divides $A_2$, $23$ divides $A_3$ and $41$ divides $A_{10} = 5765999453$. No other prime number up to $50$ divides an element in $A$.

Find $S(300000)$.

Answer: 326227335


Let $P(n)$ be the set of the first $n$ positive integers $\{1, 2, \dots, n\}$.

Let $Q(n)$ be the set of all the non-empty subsets of $P(n)$.

Let $R(n)$ be the set of all the non-empty subsets of $Q(n)$.

An element $X \in R(n)$ is a non-empty subset of $Q(n)$, so it is itself a set.

From $X$ we can construct a graph as follows:

- Each element $Y \in X$ corresponds to a vertex and labeled with $Y$;

- Two vertices $Y_1$ and $Y_2$ are connected if $Y_1 \cap Y_2 \ne \emptyset$.

For example, $X = \{\{1\},\{1,2,3\},\{3\},\{5,6\},\{6,7\}\}$ results in the following graph:

This graph has two connected components.

Let $C(n, k)$ be the number of elements of $R(n)$ that have exactly $k$ connected components in their graph.

You are given $C(2, 1) = 6$, $C(3, 1) = 111$, $C(4, 2) = 486$, $C(100, 10) \bmod 1\,000\,000\,007 = 728209718$.

Find $C(10^4, 10) \bmod 1\,000\,000\,007$.

Answer: 57717170


On a chess board, a centaur moves like a king or a knight. The diagram below shows the valid moves of a centaur (represented by an inverted king) on an $8 \times 8$ board.

It can be shown that at most $n^2$ non-attacking centaurs can be placed on a board of size $2n \times 2n$.

Let $C(n)$ be the number of ways to place $n^2$ centaurs on a $2n \times 2n$ board so that no centaur attacks another directly.

For example $C(1) = 4$, $C(2) = 25$, $C(10) = 1477721$.

Let $F_i$ be the $i$th Fibonacci number defined as $F_1 = F_2 = 1$ and $F_i = F_{i - 1} + F_{i - 2}$ for $i \gt 2$.

Find $\displaystyle \left( \sum_{i=2}^{90} C(F_i) \right) \bmod (10^8+7)$.

Answer: 89539872


The McCarthy 91 function is defined as follows:
$$
M_{91}(n) =
\begin{cases}
n - 10 & \text{if } n > 100 \\
M_{91}(M_{91}(n+11)) & \text{if } 0 \leq n \leq 100
\end{cases}
$$

We can generalize this definition by abstracting away the constants into new variables:

$$
M_{m,k,s}(n) =
\begin{cases}
n - s & \text{if } n > m \\
M_{m,k,s}(M_{m,k,s}(n+k)) & \text{if } 0 \leq n \leq m
\end{cases}
$$

This way, we have $M_{91} = M_{100,11,10}$.

Let $F_{m,k,s}$ be the set of fixed points of $M_{m,k,s}$. That is,

$$F_{m,k,s}= \left\{ n \in \mathbb{N} \, | \, M_{m,k,s}(n) = n \right\}$$

For example, the only fixed point of $M_{91}$ is $n = 91$. In other words, $F_{100,11,10}= \{91\}$.

Now, define $SF(m,k,s)$ as the sum of the elements in $F_{m,k,s}$ and let $S(p,m) = \displaystyle \sum_{1 \leq s < k \leq p}{SF(m,k,s)}$.

For example, $S(10, 10) = 225$ and $S(1000, 1000)=208724467$.

Find $S(10^6, 10^6)$.

Answer: 208517717451208352


A Gaussian integer is a number $z = a + bi$ where $a$, $b$ are integers and $i^2 = -1$.

Gaussian integers are a subset of the complex numbers, and the integers are the subset of Gaussian integers for which $b = 0$.

A Gaussian integer unit is one for which $a^2 + b^2 = 1$, i.e. one of $1, i, -1, -i$.

Let's define a proper Gaussian integer as one for which $a \gt 0$ and $b \ge 0$.

A Gaussian integer $z_1 = a_1 + b_1 i$ is said to be divisible by $z_2 = a_2 + b_2 i$ if $z_3 = a_3 + b_3 i = z_1 / z_2$ is a Gaussian integer.

$\frac {z_1} {z_2} = \frac {a_1 + b_1 i} {a_2 + b_2 i} = \frac {(a_1 + b_1 i)(a_2 - b_2 i)} {(a_2 + b_2 i)(a_2 - b_2 i)} = \frac {a_1 a_2 + b_1 b_2} {a_2^2 + b_2^2} + \frac  {a_2 b_1 - a_1 b_2}  {a_2^2 + b_2^2}i = a_3 + b_3 i$

So, $z_1$ is divisible by $z_2$ if $\frac {a_1 a_2 + b_1 b_2} {a_2^2 + b_2^2}$ and $\frac  {a_2 b_1 - a_1 b_2}  {a_2^2 + b_2^2}$ are integers.

For example, $2$ is divisible by $1 + i$ because $2/(1 + i) = 1 - i$ is a Gaussian integer.

A Gaussian prime is a Gaussian integer that is divisible only by a unit, itself or itself times a unit.

For example, $1 + 2i$ is a Gaussian prime, because it is only divisible by $1$, $i$, $-1$, $-i$, $1 + 2i$, $i(1 + 2i) = i - 2$, $-(1 + 2i) = -1 - 2i$ and $-i(1 + 2i) = 2 - i$.

$2$ is not a Gaussian prime as it is divisible by $1 + i$.

A Gaussian integer can be uniquely factored as the product of a unit and proper Gaussian primes.

For example $2 = -i(1 + i)^2$ and $1 + 3i = (1 + i)(2 + i)$.

A Gaussian integer is said to be squarefree if its prime factorization does not contain repeated proper Gaussian primes.

So $2$ is not squarefree over the Gaussian integers, but $1 + 3i$ is.

Units and Gaussian primes are squarefree by definition.

Let $f(n)$ be the count of proper squarefree Gaussian integers with $a^2 + b^2 \le n$.

For example $f(10) = 7$ because $1$, $1 + i$, $1 + 2i$, $1 + 3i = (1 + i)(2 + i)$, $2 + i$, $3$ and $3 + i = -i(1 + i)(1 + 2i)$ are squarefree, while $2 = -i(1 + i)^2$ and $2 + 2i = -i(1 + i)^3$ are not.

You are given $f(10^2) = 54$, $f(10^4) = 5218$ and $f(10^8) = 52126906$.

Find $f(10^{14})$.

Answer: 52126939292957


A triangle is cut into four pieces by two straight lines, each starting at one vertex and ending on the opposite edge. This results in forming three smaller triangular pieces, and one quadrilateral.  If the original triangle has an integral area, it is often possible to choose cuts such that all of the four pieces also have integral area.  For example, the diagram below shows a triangle of area $55$ that has been cut in this way.

Representing the areas as $a, b, c$ and $d$, in the example above, the individual areas are $a = 22$, $b = 8$, $c = 11$ and $d = 14$.  It is also possible to cut a triangle of area $55$ such that $a = 20$, $b = 2$, $c = 24$, $d = 9$.

Define a triangle cutting quadruple $(a, b, c, d)$ as a valid integral division of a triangle, where $a$ is the area of the triangle between the two cut vertices, $d$ is the area of the quadrilateral and $b$ and $c$ are the areas of the two other triangles, with the restriction that $b \le c$.  The two solutions described above are $(22,8,11,14)$ and $(20,2,24,9)$.  These are the only two possible quadruples that have a total area of $55$.

Define $S(n)$ as the sum of the area of the uncut triangles represented by all valid quadruples with $a+b+c+d \le n$.
For example, $S(20) = 259$.

Find $S(10000)$.

Answer: 2699929328


Let $r$ be the real root of the equation $x^3 = x^2 + 1$.

Every positive integer can be written as the sum of distinct increasing powers of $r$.

If we require the number of terms to be finite and the difference between any two exponents to be three or more, then the representation is unique.

For example, $3 = r^{-10} + r^{-5} + r^{-1} + r^2$ and $10 = r^{-10} + r^{-7} + r^6$.

Interestingly, the relation holds for the complex roots of the equation.

Let $w(n)$ be the number of terms in this unique representation of $n$. Thus $w(3) = 4$ and $w(10) = 3$.

More formally, for all positive integers $n$, we have:

$n = \displaystyle \sum_{k=-\infty}^\infty b_k r^k$

under the conditions that:

$b_k$ is $0$ or $1$ for all $k$;

$b_k + b_{k + 1} + b_{k + 2} \le 1$ for all $k$;

$w(n) = \displaystyle \sum_{k=-\infty}^\infty b_k$ is finite.

Let $S(m) = \displaystyle \sum_{j=1}^m w(j^2)$.

You are given $S(10) = 61$ and $S(1000) = 19403$.

Find $S(5\,000\,000)$.

Answer: 226754889


An ascent of a column $j$ in a matrix occurs if the value of column $j$ is smaller than the value of column $j + 1$ in all rows.

Let $P(k, r, n)$ be the number of $r \times n$ matrices with the following properties:

- The rows are permutations of $\{1, 2, 3, \dots, n\}$.

-  Numbering the first column as $1$, a column ascent occurs at column $j \lt n$ if and only if $j$ is not a multiple of $k$.

For example, $P(1, 2, 3) = 19$, $P(2, 4, 6) = 65508751$ and $P(7, 5, 30) \bmod 1000000123 = 161858102$.

Let $Q(n) = \displaystyle \sum_{k=1}^n P(k, n, n)$.

For example, $Q(5) = 21879393751$ and $Q(50) \bmod 1000000123 = 819573537$.

Find $Q(50000) \bmod 1000000123$.

Answer: 684724920


Coprime Nim is just like ordinary normal play Nim, but the players may only remove a number of stones from a pile that is coprime with the current size of the pile. Two players remove stones in turn. The player who removes the last stone wins.

Let $L(n, k)$ be the number of losing starting positions for the first player, assuming perfect play, when the game is played with $k$ piles, each having between $1$ and $n - 1$ stones inclusively.

For example, $L(5, 2) = 6$ since the losing initial positions are $(1, 1)$, $(2, 2)$, $(2, 4)$, $(3, 3)$, $(4, 2)$ and $(4, 4)$.

You are also given $L(10, 5) = 9964$, $L(10, 10) = 472400303$, $L(10^3, 10^3) \bmod 1\,000\,000\,007 = 954021836$.

Find $L(10^7, 10^7)\bmod 1\,000\,000\,007$.

Answer: 994345168


Let $S(n)$ be the number of pairs $(a,b)$ of distinct divisors of $n$ such that $a$ divides $b$.

For $n=6$ we get the following pairs: $(1,2), (1,3), (1,6),( 2,6)$ and $(3,6)$. So $S(6)=5$.

Let $p_m\#$ be the product of the first $m$ prime numbers,  so $p_2\# = 2*3 = 6$.

Let $E(m, n)$ be the highest integer $k$ such that $2^k$ divides $S((p_m\#)^n)$.

$E(2,1) = 0$ since $2^0$ is the highest power of 2 that divides S(6)=5.

Let $Q(n)=\sum_{i=1}^{n} E(904961, i)$

$Q(8)=2714886$.

Evaluate $Q(10^{12})$.

Answer: 452480999988235494


Construct triangle $ABC$ such that:

- Vertices $A$, $B$ and $C$ are lattice points inside or on the circle of radius $r$ centered at the origin;

- the triangle contains no other lattice point inside or on its edges;

- the perimeter is maximum.

Let $R$ be the circumradius of triangle $ABC$ and $T(r) = R/r$.

For $r = 5$, one possible triangle has vertices $(-4,-3)$, $(4,2)$ and $(1,0)$ with perimeter $\sqrt{13}+\sqrt{34}+\sqrt{89}$ and circumradius $R = \sqrt {\frac {19669} 2 }$, so $T(5) = \sqrt {\frac {19669} {50} }$.

You are given $T(10) \approx 97.26729$ and $T(100) \approx 9157.64707$.

Find $T(10^7)$. Give your answer rounded to the nearest integer.

Answer: 51208732914368


A company specialises in producing large rectangular metal sheets, starting from unit square metal plates.  The welding is performed by a range of robots of increasing size.  Unfortunately, the programming options of these robots are rather limited.  Each one can only process up to $25$ identical rectangles of metal, which they can weld along either edge to produce a larger rectangle.  The only programmable variables are the number of rectangles to be processed (up to and including $25$), and whether to weld the long or short edge.

For example, the first robot could be programmed to weld together $11$ raw unit square plates to make a $11 \times 1$ strip. The next could take $10$ of these $11 \times 1$ strips, and weld them either to make a longer $110 \times 1$ strip, or a $11 \times 10$ rectangle. Many, but not all, possible dimensions of  metal sheets can be constructed in this way.

One regular customer has a particularly unusual order: The finished product should have an exact area, and the long side must not be more than $10\%$ larger than the short side. If these requirements can be met in more than one way, in terms of the exact dimensions of the two sides, then the customer will demand that all variants be produced. For example, if the order calls for a metal sheet of area $889200$, then there are three final dimensions that can be produced: $900 \times 988$, $912 \times 975$ and $936 \times 950$. The target area of $889200$ is the smallest area which can be manufactured in three different variants, within the limitations of the robot welders.

Let $M(n)$ be the minimal area that can be manufactured in exactly $n$ variants with the longer edge not greater than $10\%$ bigger than the shorter edge. Hence $M(3) = 889200$.

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

Answer: 27186308211734760


A line segment of length $2n-3$ is randomly split into $n$ segments of integer length ($n \ge 3$). In the sequence given by this split, the segments are then used as consecutive sides of a convex $n$-polygon, formed in such a way that its area is maximal.  All of the $\binom{2n-4} {n-1}$ possibilities for splitting up the initial line segment occur with the same probability.

Let $E(n)$ be the expected value of the area that is obtained by this procedure.

For example, for $n=3$ the only possible split of the line segment of length $3$ results in three line segments with length $1$, that form an equilateral triangle with an area of $\frac 1 4 \sqrt{3}$. Therefore $E(3)=0.433013$, rounded to $6$ decimal places.

For $n=4$ you can find $4$ different possible splits, each of which is composed of three line segments with length $1$ and one line segment with length $2$. All of these splits lead to the same maximal quadrilateral with an area of $\frac 3 4 \sqrt{3}$, thus $E(4)=1.299038$, rounded to $6$ decimal places.

Let $S(k)=\displaystyle \sum_{n=3}^k E(n)$.

For example, $S(3)=0.433013$, $S(4)=1.732051$, $S(5)=4.604767$ and $S(10)=66.955511$, rounded to $6$ decimal places each.

Find $S(50)$, rounded to $6$ decimal places.

Answer: 12363.698850


Let $\sigma(n)$ be the sum of the divisors of $n$.

E.g. the divisors of $4$ are $1$, $2$ and $4$, so $\sigma(4)=7$.

The numbers $n$ not exceeding $20$ such that $7$ divides  $\sigma(n)$ are:  $4$, $12$, $13$ and $20$, the sum of these numbers being $49$.

Let $S(n, d)$ be the sum of the numbers $i$ not exceeding $n$ such that $d$ divides $\sigma(i)$.

So $S(20 , 7)=49$.

You are given: $S(10^6,2017)=150850429$ and $S(10^9, 2017)=249652238344557$.

Find $S(10^{11}, 2017)$.

Answer: 2992480851924313898


Adam plays the following game with his birthday cake.

He cuts a piece forming a circular sector of $60$ degrees and flips the piece upside down, with the icing on the bottom.

He then rotates the cake by $60$ degrees counterclockwise, cuts an adjacent $60$ degree piece and flips it upside down.

He keeps repeating this, until after a total of twelve steps, all the icing is back on top.

Amazingly, this works for any piece size, even if the cutting angle is an irrational number: all the icing will be back on top after a finite number of steps.

Now, Adam tries something different: he alternates cutting pieces of size $x=\frac{360}{9}$ degrees, $y=\frac{360}{10}$ degrees and $z=\frac{360 }{\sqrt{11}}$ degrees. The first piece he cuts has size $x$ and he flips it. The second has size $y$ and he flips it. The third has size $z$ and he flips it. He repeats this with pieces of size $x$, $y$ and $z$ in that order until all the icing is back on top, and discovers he needs $60$ flips altogether.

Let $F(a, b, c)$ be the minimum number of piece flips needed to get all the icing back on top for pieces of size $x=\frac{360}{a}$ degrees, $y=\frac{360}{b}$ degrees and $z=\frac{360}{\sqrt{c}}$ degrees.

Let $G(n) = \sum_{9 \le a \lt b \lt c \le n} F(a,b,c)$, for integers $a$, $b$ and $c$.

You are given that $F(9, 10, 11) = 60$, $F(10, 14, 16) = 506$, $F(15, 16, 17) = 785232$.

You are also given $G(11) = 60$, $G(14) = 58020$ and $G(17) = 1269260$.

Find $G(53)$.

Answer: 329569369413585


Tom has built a random generator that is connected to a row of $n$ light bulbs. Whenever the random generator is activated each of the $n$ lights is turned on with the probability of $\frac 1 2$, independently of its former state or the state of the other light bulbs.

While discussing with his friend Jerry how to use his generator, they invent two different games, they call the reciprocal games:

Both games consist of $n$ turns. Each turn is started by choosing a number $k$ randomly between (and including) $1$ and $n$, with equal probability of $\frac 1 n$ for each number, while the possible win for that turn is the reciprocal of $k$, that is $\frac 1 k$.

In game A, Tom activates his random generator once in each turn. If the number of lights turned on is the same as the previously chosen number $k$, Jerry wins and gets $\frac 1 k$, otherwise he will receive nothing for that turn. Jerry's expected win after playing the total game A consisting of $n$ turns is called $J_A(n)$. For example $J_A(6)=0.39505208$, rounded to $8$ decimal places.

For each turn in game B, after $k$ has been randomly selected, Tom keeps reactivating his random generator until exactly $k$ lights are turned on. After that Jerry takes over and reactivates the random generator until he, too, has generated a pattern with exactly $k$ lights turned on. If this pattern is identical to Tom's last pattern, Jerry wins and gets $\frac 1 k$, otherwise he will receive nothing. Jerry's expected win after the total game B consisting of $n$ turns is called $J_B(n)$. For example $J_B(6)=0.43333333$, rounded to $8$ decimal places.

Let $\displaystyle S(m)=\sum_{n=1}^m (J_A(n)+J_B(n))$. For example $S(6)=7.58932292$, rounded to $8$ decimal places.

Find $S(123456789)$, rounded to $8$ decimal places.

Answer: 75.44817535


Tom has built a random generator that is connected to a row of $n$ light bulbs. Whenever the random generator is activated each of the $n$ lights is turned on with the probability of $\frac 1 2$, independently of its former state or the state of the other light bulbs.

While discussing with his friend Jerry how to use his generator, they invent two different games, they call the reciprocal games:

Both games consist of $n$ turns. Each turn is started by choosing a number $k$ randomly between (and including) $1$ and $n$, with equal probability of $\frac 1 n$ for each number, while the possible win for that turn is the reciprocal of $k$, that is $\frac 1 k$.

In game A, Tom activates his random generator once in each turn. If the number of lights turned on is the same as the previously chosen number $k$, Jerry wins and gets $\frac 1 k$, otherwise he will receive nothing for that turn. Jerry's expected win after playing the total game A consisting of $n$ turns is called $J_A(n)$. For example $J_A(6)=0.39505208$, rounded to $8$ decimal places.

For each turn in game B, after $k$ has been randomly selected, Tom keeps reactivating his random generator until exactly $k$ lights are turned on. After that Jerry takes over and reactivates the random generator until he, too, has generated a pattern with exactly $k$ lights turned on. If this pattern is identical to Tom's last pattern, Jerry wins and gets $\frac 1 k$, otherwise he will receive nothing. Jerry's expected win after the total game B consisting of $n$ turns is called $J_B(n)$. For example $J_B(6)=0.43333333$, rounded to $8$ decimal places.

Let $D(n)=J_B(n)−J_A(n)$. For example, $D(6) = 0.03828125$.

Find the $7$ most significant digits of $D(123456789)$ after removing all leading zeros.

(If, for example, we had asked for the $7$ most significant digits of $D(6)$, the answer would have been 3828125.)

Answer: 4228020


A mountain range consists of a line of mountains with slopes of exactly $45^\circ$, and heights governed by the prime numbers, $p_n$. The up-slope of the $k$th mountain is of height $p_{2k - 1}$, and the downslope is $p_{2k}$. The first few foot-hills of this range are illustrated below.

Tenzing sets out to climb each one in turn, starting from the lowest. At the top of each peak, he looks back and counts how many of the previous peaks he can see. In the example above, the eye-line from the third mountain is drawn in red, showing that he can only see the peak of the second mountain from this viewpoint. Similarly, from the $9$th mountain, he can see three peaks, those of the $5$th, $7$th and $8$th mountain.

Let $P(k)$ be the number of peaks that are visible looking back from the $k$th mountain.  Hence $P(3)=1$ and $P(9)=3$.

Also $\displaystyle \sum_{k=1}^{100} P(k) = 227$.

Find $\displaystyle \sum_{k=1}^{2500000} P(k)$.

Answer: 21025060


A snowflake of order $n$ is formed by overlaying an equilateral triangle (rotated by $180$ degrees) onto each equilateral triangle of the same size in a snowflake of order $n-1$. A snowflake of order $1$ is a single equilateral triangle.

Some areas of the snowflake are overlaid repeatedly. In the above picture, blue represents the areas that are one layer thick, red two layers thick, yellow three layers thick, and so on.

For an order $n$ snowflake, let $A(n)$ be the number of triangles that are one layer thick, and let $B(n)$ be the number of triangles that are three layers thick. Define $G(n) = \gcd(A(n), B(n))$.

E.g. $A(3) = 30$, $B(3) = 6$, $G(3)=6$.

$A(11) = 3027630$, $B(11) = 19862070$, $G(11) = 30$.

Further, $G(500) = 186$ and $\sum_{n=3}^{500}G(n)=5124$.

Find $\displaystyle \sum_{n=3}^{10^7}G(n)$.

Answer: 271197444


A positive number is pandigital in base $b$ if it contains all digits from $0$ to $b - 1$ at least once when written in base $b$.

An $n$-super-pandigital number is a number that is simultaneously pandigital in all bases from $2$ to $n$ inclusively.

For example $978 = 1111010010_2 = 1100020_3 = 33102_4 = 12403_5$ is the smallest $5$-super-pandigital number.

Similarly, $1093265784$ is the smallest $10$-super-pandigital number.

The sum of the $10$ smallest $10$-super-pandigital numbers is $20319792309$.

What is the sum of the $10$ smallest $12$-super-pandigital numbers?

Answer: 30510390701978


A matrix $M$ is called idempotent if $M^2 = M$.

Let $M$ be a three by three matrix :
$M=\begin{pmatrix}
a & b & c\\
d & e & f\\
g &h &i\\
\end{pmatrix}$.

Let $C(n)$ be the number of idempotent three by three matrices $M$ with integer elements such that

$ -n \le a,b,c,d,e,f,g,h,i \le n$.

$C(1)=164$ and $C(2)=848$.

Find $C(200)$.

Answer: 19737656


$n$ runners in very different training states want to compete in a race. Each one of them is given a different starting number $k$ $(1\leq k \leq n)$ according to the runner's (constant) individual racing speed being $v_k=\frac{k}{n}$.

In order to give the slower runners a chance to win the race, $n$ different starting positions are chosen randomly (with uniform distribution) and independently from each other within the racing track of length $1$. After this, the starting position nearest to the goal is assigned to runner $1$, the next nearest starting position to runner $2$ and so on, until finally the starting position furthest away from the goal is assigned to runner $n$. The winner of the race is the runner who reaches the goal first.

Interestingly, the expected running time for the winner is $\frac{1}{2}$, independently of the number of runners. Moreover, while it can be shown that all runners will have the same expected running time of $\frac{n}{n+1}$, the race is still unfair, since the winning chances may differ significantly for different starting numbers:

Let $P_{n,k}$ be the probability for runner $k$ to win a race with $n$ runners and $E_n = \sum_{k=1}^n k P_{n,k}$ be the expected starting number of the winner in that race. It can be shown that, for example,
$P_{3,1}=\frac{4}{9}$, $P_{3,2}=\frac{2}{9}$, $P_{3,3}=\frac{1}{3}$ and $E_3=\frac{17}{9}$ for a race with $3$ runners.

You are given that $E_4=2.21875$, $E_5=2.5104$ and $E_{10}=3.66021568$.

Find $E_{1000000}$ rounded to $4$ digits after the decimal point.

Answer: 1252.9809


Let $q$ be a prime and $A \ge B >0$ be two integers with the following properties:

-  $A$ and $B$ have no prime factor in common, that is $\gcd(A,B)=1$.

-  The product $AB$ is divisible by every prime less than q.

It can be shown that, given these conditions, any sum $A+B<q^2$ and any difference $1<A-B<q^2$ has to be a prime number. Thus you can verify that a number $p$ is prime by showing that either $p=A+B<q^2$ or $p=A-B<q^2$ for some $A,B,q$ fulfilling the conditions listed above.

Let $V(p)$ be the smallest possible value of $A$ in any sum $p=A+B$ and any difference $p=A-B$, that verifies $p$ being prime. Examples:

$V(2)=1$, since $2=1+1< 2^2$.

$V(37)=22$, since $37=22+15=2 \cdot 11+3 \cdot 5< 7^2$ is the associated sum with the smallest possible $A$.

$V(151)=165$ since $151=165-14=3 \cdot 5 \cdot 11 - 2 \cdot 7<13^2$ is the associated difference with the smallest possible $A$.

Let $S(n)$ be the sum of $V(p)$ for all primes $p<n$. For example, $S(10)=10$ and $S(200)=7177$.

Find $S(3800)$.

Answer: 5780447552057000454


It was quite an ordinary day when a mysterious alien vessel appeared as if from nowhere. After waiting several hours and receiving no response it is decided to send a team to investigate, of which you are included. Upon entering the vessel you are met by a friendly holographic figure, Katharina, who explains the purpose of the vessel, Eulertopia.

She claims that Eulertopia is almost older than time itself. Its mission was to take advantage of a combination of incredible computational power and vast periods of time to discover the answer to life, the universe, and everything. Hence the resident cleaning robot, Leonhard, along with his housekeeping responsibilities, was built with a powerful computational matrix to ponder the meaning of life as he wanders through a massive 1000 by 1000 square grid of rooms. She goes on to explain that the rooms are numbered sequentially from left to right, row by row. So, for example, if Leonhard was wandering around a 5 by 5 grid then the rooms would be numbered in the following way.

Many millenia ago Leonhard reported to Katharina to have found the answer and he is willing to share it with any life form who proves to be worthy of such knowledge.

Katharina further explains that the designers of Leonhard were given instructions to program him with equal probability of remaining in the same room or travelling to an adjacent room. However, it was not clear to them if this meant (i) an equal probability being split equally between remaining in the room and the number of available routes, or, (ii) an equal probability (50%) of remaining in the same room and then the other 50% was to be split equally between the number of available routes.

(i) Probability of remaining related to number of exits

(ii) Fixed 50% probability of remaining

The records indicate that they decided to flip a coin. Heads would mean that the probability of remaining was dynamically related to the number of exits whereas tails would mean that they program Leonhard with a fixed 50% probability of remaining in a particular room. Unfortunately there is no record of the outcome of the coin, so without further information we would need to assume that there is equal probability of either of the choices being implemented.

Katharina suggests it should not be too challenging to determine that the probability of finding him in a square numbered room in a 5 by 5 grid after unfathomable periods of time would be approximately 0.177976190476 [12 d.p.].

In order to prove yourself worthy of visiting the great oracle you must calculate the probability of finding him in a square numbered room in the 1000 by 1000 lair in which he has been wandering.

(Give your answer rounded to 12 decimal places)

Answer: 0.000989640561


A bouncing point moves counterclockwise along a circle with circumference $1$ with jumps of constant length $l \lt 1$, until it hits a gap of length $g \lt 1$, that is placed in a distance $d$ counterclockwise from the starting point. The gap does not include the starting point, that is $g+d \lt 1$.

Let $S(l,g,d)$ be the sum of the length of all jumps, until the point falls into the gap. It can be shown that $S(l,g,d)$ is finite for any irrational jump size $l$, regardless of the values of $g$ and $d$.

Examples:

$S(\sqrt{\frac 1 2}, 0.06, 0.7)=0.7071 \cdots$, $S(\sqrt{\frac 1 2}, 0.06, 0.3543)=1.4142 \cdots$ and
$S(\sqrt{\frac 1 2}, 0.06, 0.2427)=16.2634 \cdots$.

Let $M(n, g)$ be the maximum of $ \sum S(\sqrt{\frac 1 p}, g, d)$ for all primes $p \le n$ and any valid value of $d$.

Examples:

$M(3, 0.06) =29.5425 \cdots$, since $S(\sqrt{\frac 1 2}, 0.06, 0.2427)+S(\sqrt{\frac 1 3}, 0.06, 0.2427)=29.5425 \cdots$ is the maximal reachable sum for $g=0.06$.

$M(10, 0.01)=266.9010 \cdots$

Find $M(100, 0.00002)$, rounded to $4$ decimal places.

Answer: 344457.5871


An equilateral triangle with integer side length $n \ge 3$ is divided into $n^2$ equilateral triangles with side length 1 as shown in the diagram below.

The vertices of these triangles constitute a triangular lattice with $\frac{(n+1)(n+2)} 2$ lattice points.

Let $H(n)$ be the number of all regular hexagons that can be found by connecting 6 of these points.

For example, $H(3)=1$, $H(6)=12$ and $H(20)=966$.

Find $\displaystyle \sum_{n=3}^{12345} H(n)$.

Answer: 265695031399260211


Any positive integer can be written as a product of prime powers: $p_1^{a_1} \times p_2^{a_2} \times \cdots \times p_k^{a_k}$,

where $p_i$ are distinct prime integers, $a_i \gt 0$ and $p_i \lt p_j$ if $i \lt j$.

A decreasing prime power positive integer is one for which $a_i \ge a_j$ if $i \lt j$.

For example, $1$, $2$, $15=3 \times 5$, $360=2^3 \times 3^2 \times 5$ and $1000=2^3 \times 5^3$ are decreasing prime power integers.

Let $C(n)$ be the count of decreasing prime power positive integers not exceeding $n$.

$C(100) = 94$ since all positive integers not exceeding $100$ have decreasing prime powers except $18$, $50$, $54$, $75$, $90$ and $98$.

You are given $C(10^6) = 922052$.

Find $C(10^{13})$.

Answer: 9219696799346


A lattice cube is a cube in which all vertices have integer coordinates. Let $C(n)$ be the number of different lattice cubes in which the coordinates of all vertices range between (and including) $0$ and $n$. Two cubes are hereby considered different if any of their vertices have different coordinates.

For example, $C(1)=1$, $C(2)=9$, $C(4)=100$, $C(5)=229$, $C(10)=4469$ and $C(50)=8154671$.

Different cubes may contain different numbers of lattice points.

For example, the cube with the vertices

$(0, 0, 0)$, $(3, 0, 0)$, $(0, 3, 0)$, $(0, 0, 3)$, $(0, 3, 3)$, $(3, 0, 3)$, $(3, 3, 0)$, $(3, 3, 3)$ contains $64$ lattice points ($56$ lattice points on the surface including the $8$ vertices and $8$ points within the cube).

In contrast, the cube with the vertices

$(0, 2, 2)$, $(1, 4, 4)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 2, 5)$, $(3, 5, 2)$, $(4, 1, 1)$, $(5, 3, 3)$ contains only $40$ lattice points ($20$ points on the surface and $20$ points within the cube), although both cubes have the same side length $3$.

Let $S(n)$ be the sum of the lattice points contained in the different lattice cubes in which the coordinates of all vertices range between (and including) $0$ and $n$.

For example, $S(1)=8$, $S(2)=91$, $S(4)=1878$, $S(5)=5832$, $S(10)=387003$ and $S(50)=29948928129$.

Find $S(5000) \bmod 10^9$.

Answer: 3805524


A Hilbert number is any positive integer of the form $4k+1$ for integer $k\geq 0$.  We shall define a squarefree Hilbert number as a Hilbert number which is not divisible by the square of any Hilbert number other than one.  For example, $117$ is a squarefree Hilbert number, equaling $9\times13$.  However $6237$ is a Hilbert number that is not squarefree in this sense, as it is divisible by $9^2$.  The number $3969$ is also not squarefree, as it is divisible by both $9^2$ and $21^2$.

There are $2327192$ squarefree Hilbert numbers below $10^7$.

How many squarefree Hilbert numbers are there below $10^{16}$?

Answer: 2327213148095366


A number is $p$-smooth if it has no prime factors larger than $p$.

Let $T$ be the sequence of triangular numbers, i.e. $T(n)=n(n+1)/2$.

Find the sum of all indices $n$ such that $T(n)$ is $47$-smooth.

Answer: 2227616372734


Let $a, b$ and $c$ be the sides of an integer sided triangle with one angle of $120$ degrees, $a \le b \le c$ and $b-a \le 100$.

Let $T(n)$ be the number of such triangles with $c \le n$.

$T(1000)=235$ and $T(10^8)=1245$.

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

Answer: 19903


A standard envelope shape is a convex figure consisting of an isosceles triangle (the flap) placed on top of a rectangle.  An example of an envelope with integral sides is shown below.  Note that to form a sensible envelope, the perpendicular height of the flap ($BCD$) must be smaller than the height of the rectangle ($ABDE$).

In the envelope illustrated, not only are all the sides integral, but also all the diagonals ($AC$, $AD$, $BD$, $BE$ and $CE$) are integral too. Let us call an envelope with these properties a Heron envelope.

Let $S(p)$ be the sum of the perimeters of all the Heron envelopes with a perimeter less than or equal to $p$.

You are given that $S(10^4) = 884680$. Find $S(10^7)$.

Answer: 1174137929000


A long long time ago in a galaxy far far away, the Wimwians, inhabitants of planet WimWi, discovered an unmanned drone that had landed on their planet. On examining the drone, they uncovered a device that sought the answer for the so called "Birthday Problem". The description of the problem was as follows:

If people on your planet were to enter a very large room one by one, what will be the expected number of people in the room when you first find 3 people with Birthdays within 1 day from each other.

The description further instructed them to enter the answer into the device and send the drone into space again. Startled by this turn of events, the Wimwians consulted their best mathematicians. Each year on Wimwi has 10 days and the mathematicians assumed equally likely birthdays and ignored leap years (leap years in Wimwi have 11 days), and found 5.78688636 to be the required answer. As such, the Wimwians entered this answer and sent the drone back into space.

After traveling light years away, the drone then landed on planet Joka. The same events ensued except this time, the numbers in the device had changed due to some unknown technical issues. The description read:

If people on your planet were to enter a very large room one by one, what will be the expected number of people in the room when you first find 3 people with Birthdays within 7 days from each other.

With a 100-day year on the planet, the Jokars (inhabitants of Joka) found the answer to be 8.48967364 (rounded to 8 decimal places because the device allowed only 8 places after the decimal point) assuming equally likely birthdays. They too entered the answer into the device and launched the drone into space again.

This time the drone landed on planet Earth. As before the numbers in the problem description had changed. It read:

If people on your planet were to enter a very large room one by one, what will be the expected number of people in the room when you first find 4 people with Birthdays within 7 days from each other.

What would be the answer (rounded to eight places after the decimal point) the people of Earth have to enter into the device for a year with 365 days? Ignore leap years. Also assume that all birthdays are equally likely and independent of each other.

Answer: 32.83822408


Consider the term $\small \sqrt{x+\sqrt{y}+\sqrt{z}}$ that is representing a nested square root. $x$, $y$ and $z$ are positive integers and $y$ and $z$ are not allowed to be perfect squares, so the number below the outer square root is irrational. Still it can be shown that for some combinations of $x$, $y$ and $z$ the given term can be simplified into a sum and/or difference of simple square roots of integers, actually denesting the square roots in the initial expression.

Here are some examples of this denesting:

$\small \sqrt{3+\sqrt{2}+\sqrt{2}}=\sqrt{2}+\sqrt{1}=\sqrt{2}+1$

$\small \sqrt{8+\sqrt{15}+\sqrt{15}}=\sqrt{5}+\sqrt{3}$

$\small \sqrt{20+\sqrt{96}+\sqrt{12}}=\sqrt{9}+\sqrt{6}+\sqrt{3}-\sqrt{2}=3+\sqrt{6}+\sqrt{3}-\sqrt{2}$

$\small \sqrt{28+\sqrt{160}+\sqrt{108}}=\sqrt{15}+\sqrt{6}+\sqrt{5}-\sqrt{2}$

As you can see the integers used in the denested expression may also be perfect squares resulting in further simplification.

Let F($n$) be the number of different terms $\small \sqrt{x+\sqrt{y}+\sqrt{z}}$, that can be denested into the sum and/or difference of a finite number of square roots, given the additional condition that $0<x \le n$. That is,

$\small \displaystyle \sqrt{x+\sqrt{y}+\sqrt{z}}=\sum_{i=1}^k s_i\sqrt{a_i}$

with $k$, $x$, $y$, $z$ and all $a_i$ being positive integers, all $s_i =\pm 1$ and $x\le n$.
Furthermore $y$ and $z$  are not allowed to be perfect squares.

Nested roots with the same value are not considered different, for example $\small \sqrt{7+\sqrt{3}+\sqrt{27}}$, $\small \sqrt{7+\sqrt{12}+\sqrt{12}}$ and $\small \sqrt{7+\sqrt{27}+\sqrt{3}}$, that can all three be denested into $\small 2+\sqrt{3}$, would only be counted once.

You are given that $F(10)=17$, $F(15)=46$, $F(20)=86$, $F(30)=213$ and $F(100)=2918$ and $F(5000)=11134074$.

Find $F(5000000)$.

Answer: 17714439395932


The number $209$ can be expressed as $a^2 + 3ab + b^2$ in two distinct ways:

$ \qquad 209 = 8^2 + 3\cdot 8\cdot 5 + 5^2$

$ \qquad 209 = 13^2 + 3\cdot13\cdot 1 + 1^2$

Let $f(n,r)$ be the number of integers $k$ not exceeding $n$ that can be expressed as $k=a^2 + 3ab + b^2$, with $a \gt b \gt 0$ integers, in exactly $r$ different ways.

You are given that $f(10^5, 4) = 237$ and $f(10^8, 6) = 59517$.

Find $f(10^{15}, 40)$.

Answer: 82490213


A square is drawn around a circle as shown in the diagram below on the left.

We shall call the blue shaded region the L-section.

A line is drawn from the bottom left of the square to the top right as shown in the diagram on the right.

We shall call the orange shaded region a concave triangle.

It should be clear that the concave triangle occupies exactly half of the L-section.

Two circles are placed next to each other horizontally, a rectangle is drawn around both circles, and a line is drawn from the bottom left to the top right as shown in the diagram below.

This time the concave triangle occupies approximately 36.46% of the L-section.

If $n$ circles are placed next to each other horizontally, a rectangle is drawn around the n circles, and a line is drawn from the bottom left to the top right, then it can be shown that the least value of n for which the concave triangle occupies less than 10% of the L-section is $n = 15$.

What is the least value of $n$ for which the concave triangle occupies less than 0.1% of the L-section?

Answer: 2240


The coefficients in the expansion of $(x+1)^k$ are called binomial coefficients.

Analoguously the coefficients in the expansion of $(x^4+x^3+x^2+x+1)^k$ are called quintinomial coefficients.
(quintus= Latin for fifth).

Consider the expansion of $(x^4+x^3+x^2+x+1)^3$:

$x^{12}+3x^{11}+6x^{10}+10x^9+15x^8+18x^7+19x^6+18x^5+15x^4+10x^3+6x^2+3x+1$

As we can see $7$ out of the $13$ quintinomial coefficients for $k=3$ are odd.

Let $Q(k)$ be the number of odd coefficients in the expansion of $(x^4+x^3+x^2+x+1)^k$.

So $Q(3)=7$.

You are given $Q(10)=17$ and $Q(100)=35$.

Find $\sum_{k=1}^{18}Q(10^k)$.

Answer: 11651930052


Christopher Robin and Pooh Bear love the game of Poohsticks so much that they invented a new version which allows them to play for longer before one of them wins and they have to go home for tea. The game starts as normal with both dropping a stick simultaneously on the upstream side of a bridge. But rather than the game ending when one of the sticks emerges on the downstream side, instead they fish their sticks out of the water, and drop them back in again on the upstream side. The game only ends when one of the sticks emerges from under the bridge ahead of the other one having also 'lapped' the other stick - that is, having made one additional journey under the bridge compared to the other stick.

On a particular day when playing this game, the time taken for a stick to travel under the bridge varies between a minimum of 30 seconds, and a maximum of 60 seconds. The time taken to fish a stick out of the water and drop it back in again on the other side is 5 seconds. The current under the bridge has the unusual property that the sticks' journey time is always an integral number of seconds, and it is equally likely to emerge at any of the possible times between 30 and 60 seconds (inclusive). It turns out that under these circumstances, the expected time for playing a single game is 1036.15 seconds (rounded to 2 decimal places). This time is measured from the point of dropping the sticks for the first time, to the point where the winning stick emerges from under the bridge having lapped the other.

The stream flows at different rates each day, but maintains the property that the journey time in seconds is equally distributed amongst the integers from a minimum, $n$, to a maximum, $m$, inclusive. Let the expected time of play in seconds be $E(m,n)$. Hence $E(60,30)=1036.15...$

Let $S(k)=\sum_{m=2}^k\sum_{n=1}^{m-1}E(m,n)$.

For example $S(5)=7722.82$ rounded to 2 decimal places.

Find $S(100)$ and give your answer rounded to 2 decimal places.

Answer: 131776959.25


Let $H(n)$ denote the number of sets of positive integers such that the least common multiple of the integers in the set equals $n$.

E.g.:

The integers in the following ten sets all have a least common multiple of $6$:

$\{2,3\}$, $\{1,2,3\}$, $\{6\}$, $\{1,6\}$, $\{2,6\}$, $\{1,2,6\}$, $\{3,6\}$, $\{1,3,6\}$, $\{2,3,6\}$ and $\{1,2,3,6\}$.

Thus $H(6)=10$.

Let $L(n)$ denote the least common multiple of the numbers $1$ through $n$.

E.g. $L(6)$ is the least common multiple of the numbers $1,2,3,4,5,6$ and $L(6)$ equals $60$.

Let $HL(n)$ denote $H(L(n))$.

You are given $HL(4)=H(12)=44$.

Find $HL(50000)$. Give your answer modulo $10^9$.

Answer: 834171904


Given a non-square integer $d$, any real $x$ can be approximated arbitrarily close by quadratic integers $a+b\sqrt{d}$, where $a,b$ are integers. For example, the following inequalities approximate $\pi$ with precision $10^{-13}$:

$$4375636191520\sqrt{2}-6188084046055 < \pi < 721133315582\sqrt{2}-1019836515172 $$

We call $BQA_d(x,n)$ the quadratic integer closest to $x$ with the absolute values of $a,b$ not exceeding $n$.
We also define the integral part of a quadratic integer as $I_d(a+b\sqrt{d}) = a$.

You are given that:

- $BQA_2(\pi,10) = 6 - 2\sqrt{2}$

- $BQA_5(\pi,100)=26\sqrt{5}-55$

- $BQA_7(\pi,10^6)=560323 - 211781\sqrt{7}$

- $I_2(BQA_2(\pi,10^{13}))=-6188084046055$

Find the sum of $|I_d(BQA_d(\pi,10^{13}))|$ for all  non-square positive integers less than 100.

Answer: 526007984625966


For any $N$, let $f(N)$ be the last twelve hexadecimal digits before the trailing zeroes in $N!$.

For example, the hexadecimal representation of $20!$ is 21C3677C82B40000,

so $f(20)$ is the digit sequence 21C3677C82B4.

Find $f(20!)$. Give your answer as twelve hexadecimal digits, using uppercase for the digits A to F.

Answer: 13415DF2BE9C


We define two sequences $S = \{S(1), S(2), ..., S(n)\}$ and $S_2 = \{S_2(1), S_2(2), ..., S_2(n)\}$:

$S(k) = (p_k)^k \bmod 10007$ where $p_k$ is the $k$th prime number.

$S_2(k) = S(k) + S(\lfloor\frac{k}{10000}\rfloor + 1)$ where $\lfloor \cdot \rfloor$ denotes the floor function.

Then let $M(i, j)$ be the median of elements $S_2(i)$ through $S_2(j)$, inclusive. For example, $M(1, 10) = 2021.5$ and $M(10^2, 10^3) = 4715.0$.

Let $F(n, k) = \sum_{i=1}^{n-k+1} M(i, i + k - 1)$. For example, $F(100, 10) = 463628.5$ and $F(10^5, 10^4) = 675348207.5$.

Find $F(10^7, 10^5)$. If the sum is not an integer, use $.5$ to denote a half. Otherwise, use $.0$ instead.

Answer: 96632320042.0


For a polygon $P$, let $t(P)$ be the number of ways in which $P$ can be tiled using rhombi and squares with edge length 1. Distinct rotations and reflections are counted as separate tilings.

For example, if $O$ is a regular octagon with edge length 1, then $t(O) = 8$. As it happens, all these 8 tilings are rotations of one another:

Let $O_{a,b}$ be the equal-angled convex octagon whose edges alternate in length between $a$ and $b$.

For example, here is $O_{2,1}$, with one of its tilings:

You are given that $t(O_{1,1})=8$, $t(O_{2,1})=76$ and $t(O_{3,2})=456572$.

Find $t(O_{4,2})$.

Answer: 47067598


A deck of cards numbered from $1$ to $n$ is shuffled randomly such that each permutation is equally likely.

The cards are to be sorted into ascending order using the following technique:

-  Look at the initial sequence of cards.  If it is already sorted, then there is no need for further action.  Otherwise, if any subsequences of cards happen to be in the correct place relative to one another (ascending with no gaps), then those subsequences are fixed by attaching the cards together.  For example, with $7$ cards initially in the order 4123756, the cards labelled 1, 2 and 3 would be attached together, as would 5 and 6.

-  The cards are 'shuffled' by being thrown into the air, but note that any correctly sequenced cards remain attached, so their orders are maintained.  The cards (or bundles of attached cards) are then picked up randomly.  You should assume that this randomisation is unbiased, despite the fact that some cards are single, and others are grouped together.

-  Repeat steps 1 and 2 until the cards are sorted.

Let $S(n)$ be the expected number of shuffles needed to sort the cards. Since the order is checked before the first shuffle, $S(1) = 0$. You are given that $S(2) = 1$, and $S(5) = 4213/871$.

Find $S(52)$, and give your answer rounded to $8$ decimal places.

Answer: 54.17529329


Let $T(r)$ be the number of integer quadruplets $x, y, z, t$ such that $x^2 + y^2 + z^2 + t^2 \le r^2$. In other words, $T(r)$ is the number of lattice points in the four-dimensional hyperball of radius $r$.

You are given that $T(2) = 89$, $T(5) = 3121$, $T(100) = 493490641$ and $T(10^4) = 49348022079085897$.

Find $T(10^8) \bmod 1000000007$.

Answer: 734582049


The Torpids are rowing races held annually in Oxford, following some curious rules:

-
A division consists of $n$ boats (typically 13), placed in order based on past performance.

-
All boats within a division start at 40 metre intervals along the river, in order with the highest-placed boat starting furthest upstream.

-
The boats all start rowing simultaneously, upstream, trying to catch the boat in front while avoiding being caught by boats behind.

-
Each boat continues rowing until either it reaches the finish line or it catches up with ("bumps") a boat in front.

-
The finish line is a distance $L$ metres (the course length, in reality about 1800 metres) upstream from the starting position of the lowest-placed boat. (Because of the staggered starting positions, higher-placed boats row a slightly shorter course than lower-placed boats.)

-
When a "bump" occurs, the "bumping" boat takes no further part in the race. The "bumped" boat must continue, however, and may even be "bumped" again by boats that started two or more places behind it.

-
After the race, boats are assigned new places within the division, based on the bumps that occurred. Specifically, for any boat $A$ that started in a lower place than $B$, then $A$ will be placed higher than $B$ in the new order if and only if one of the following occurred:

-  $A$ bumped $B$ directly

-  $A$ bumped another boat that went on to bump $B$

-  $A$ bumped another boat, that bumped yet another boat, that bumped $B$

-  etc

NOTE: For the purposes of this problem you may disregard the boats' lengths, and assume that a bump occurs precisely when the two boats draw level. (In reality, a bump is awarded as soon as physical contact is made, which usually occurs when there is much less than a full boat length's overlap.)

Suppose that, in a particular race, each boat $B_j$ rows at a steady speed $v_j = -$log$X_j$ metres per second, where the $X_j$ are chosen randomly (with uniform distribution) between 0 and 1, independently from one another. These speeds are relative to the riverbank: you may disregard the flow of the river.

Let $p(n,L)$ be the probability that the new order is an even permutation of the starting order, when there are $n$ boats in the division and $L$ is the course length.

For example, with $n=3$ and $L=160$, labelling the boats as $A$,$B$,$C$ in starting order with $C$ highest, the different possible outcomes of the race are as follows:

| Bumps occurring | New order | Permutation | Probability |
| --- | --- | --- | --- |
| none | $A$, $B$, $C$ | even | $4/15$ |
| $B$ bumps $C$ | $A$, $C$, $B$ | odd | $8/45$ |
| $A$ bumps $B$ | $B$, $A$, $C$ | odd | $1/3$ |
| $B$ bumps $C$, then $A$ bumps $C$ | $C$, $A$, $B$ | even | $4/27$ |
| $A$ bumps $B$, then $B$ bumps $C$ | $C$, $B$, $A$ | odd | $2/27$ |

Therefore, $p(3,160) = 4/15 + 4/27 = 56/135$.

You are also given that $p(4,400)=0.5107843137$, rounded to 10 digits after the decimal point.

Find $p(13,1800)$ rounded to 10 digits after the decimal point.

Answer: 0.5001817828


Consider the number $48$.

There are five pairs of integers $a$ and $b$ ($a \leq b$) such that $a \times b=48$: $(1,48)$, $(2,24)$, $(3,16)$, $(4,12)$ and $(6,8)$.

It can be seen that both $6$ and $8$ have $4$ divisors.

So of those five pairs one consists of two integers with the same number of divisors.

In general:

Let $C(n)$ be the number of pairs of positive integers $a \times b=n$, ($a \leq b$) such that $a$ and $b$ have the same number of divisors;
so $C(48)=1$.

You are given $C(10!)=3$: $(1680, 2160)$, $(1800, 2016)$ and $(1890,1920)$.

Find $C(100!)$.

Answer: 543194779059


The well-known Rubik's Cube puzzle has many fascinating mathematical properties. The 2×2×2 variant has 8 cubelets with a total of 24 visible faces, each with a coloured sticker. Successively turning faces will rearrange the cubelets, although not all arrangements of cubelets are reachable without dismantling the puzzle.

Suppose that we wish to apply new stickers to a 2×2×2 Rubik's cube in a non-standard colouring. Specifically, we have $n$ different colours available (with an unlimited supply of stickers of each colour), and we place one sticker on each of the 24 faces in any arrangement that we please. We are not required to use all the colours, and if desired the same colour may appear in more than one face of a single cubelet.

We say that two such colourings $c_1,c_2$ are essentially distinct if a cube coloured according to $c_1$ cannot be made to match a cube coloured according to $c_2$ by performing mechanically possible Rubik's Cube moves.

For example, with two colours available, there are 183 essentially distinct colourings.

How many essentially distinct colourings are there with 10 different colours available?

Answer: 12395526079546335


Let $H(n)$ be the number of distinct integer sided equiangular convex hexagons with perimeter not exceeding $n$.

Hexagons are distinct if and only if they are not congruent.

You are given $H(6) = 1$, $H(12) = 10$, $H(100) = 31248$.

Find $H(55106)$.

Equiangular hexagons with perimeter not exceeding $12$

Answer: 2668608479740672


For every positive number $n$ we define the function $\mathop{streak}(n)=k$ as the smallest positive integer $k$ such that $n+k$ is not divisible by $k+1$.

E.g:

$13$ is divisible by $1$

$14$ is divisible by $2$

$15$ is divisible by $3$

$16$ is divisible by $4$

$17$ is NOT divisible by $5$

So $\mathop{streak}(13) = 4$.

Similarly:

$120$ is divisible by $1$

$121$ is NOT divisible by $2$

So $\mathop{streak}(120) = 1$.

Define $P(s, N)$ to be the number of integers $n$, $1 \lt n \lt N$, for which $\mathop{streak}(n) = s$.

So $P(3, 14) = 1$ and $P(6, 10^6) = 14286$.

Find the sum, as $i$ ranges from $1$ to $31$, of $P(i, 4^i)$.

Answer: 1617243


Alice enlists the help of some friends to generate a random number, using a single unfair coin. She and her friends sit around a table and, starting with Alice, they take it in turns to toss the coin. Everyone keeps a count of how many heads they obtain individually. The process ends as soon as Alice obtains a Head. At this point, Alice multiplies all her friends' Head counts together to obtain her random number.

As an illustration, suppose Alice is assisted by Bob, Charlie, and Dawn, who are seated round the table in that order, and that they obtain the sequence of Head/Tail outcomes THHH—TTTT—THHT—H beginning and ending with Alice. Then Bob and Charlie each obtain 2 heads, and Dawn obtains 1 head. Alice's random number is therefore $2\times 2\times 1 = 4$.

Define $e(n, p)$ to be the expected value of Alice's random number, where $n$ is the number of friends helping (excluding Alice herself), and $p$ is the probability of the coin coming up Tails.

It turns out that, for any fixed $n$, $e(n, p)$ is always a polynomial in $p$. For example, $e(3, p) = p^3 + 4p^2 + p$.

Define $c(n, k)$ to be the coefficient of $p^k$ in the polynomial $e(n, p)$. So $c(3, 1) = 1$, $c(3, 2) = 4$, and $c(3, 3) = 1$.

You are given that $c(100, 40) \equiv 986699437 \text{ } (\text{mod } 10^9+7)$.

Find $c(10000000, 4000000) \mod 10^9+7$.

Answer: 269496760


Let $S(n)$ be the sum of all contiguous integer-substrings that can be formed from the integer $n$. The substrings need not be distinct.

For example, $S(2024) = 2 + 0 + 2 + 4 + 20 + 02 + 24 + 202 + 024 + 2024 = 2304$.

Let $P(n)$ be the integer formed by concatenating the first $n$ primes together. For example, $P(7) = 2357111317$.

Let $C(n, k)$ be the integer formed by concatenating $k$ copies of $P(n)$ together. For example, $C(7, 3) = 235711131723571113172357111317$.

Evaluate $S(C(10^6, 10^{12})) \bmod (10^9 + 7)$.

Answer: 879476477


Let $F(N)$ be the maximum number of lattice points in an axis-aligned $N\times N$ square that the graph of a single strictly convex increasing function can pass through.

You are given that $F(1) = 2$, $F(3) = 3$,  $F(9) = 6$, $F(11) = 7$, $F(100) = 30$ and $F(50000) = 1898$.

Below is the graph of a function reaching the maximum $3$ for $N=3$:

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

Answer: 1398582231101


Consider an $n$-player game played in consecutive pairs: Round $1$ takes place between players $1$ and $2$, round $2$ takes place between players $2$ and $3$, and so on and so forth, all the way up to round $n$, which takes place between players $n$ and $1$. Then round $n+1$ takes place between players $1$ and $2$ as the entire cycle starts again.

In other words, during round $r$, player $((r-1) \bmod n) + 1$ faces off against player $(r \bmod n) + 1$.

During each round, a fair coin is tossed to decide which of the two players wins that round. If any given player wins both rounds $r$ and $r+1$, then that player wins the entire game.

Let $P_n(k)$ be the probability that player $k$ wins in an $n$-player game, in the form of a reduced fraction. For example, $P_3(1) = 12/49$ and $P_6(2) = 368/1323$.

Let $M_n(k)$ be the product of the reduced numerator and denominator of $P_n(k)$. For example, $M_3(1) = 588$ and $M_6(2) = 486864$.

Find the last $8$ digits of $M_{10^8+7}(10^4+7)$.

Answer: 59992576


A gozinta chain for $n$ is a sequence $\{1,a,b,\dots,n\}$ where each element properly divides the next.

For example, there are eight distinct gozinta chains for $12$:

$\{1,12\}$, $\{1,2,12\}$, $\{1,2,4,12\}$, $\{1,2,6,12\}$, $\{1,3,12\}$, $\{1,3,6,12\}$, $\{1,4,12\}$ and $\{1,6,12\}$.

Let $S(n)$ be the sum of all numbers, $k$, not exceeding $n$, which have $252$ distinct gozinta chains.

You are given $S(10^6)=8462952$ and $S(10^{12})=623291998881978$.

Find $S(10^{36})$, giving the last nine digits of your answer.

Answer: 158452775


Frodo and Sam need to travel 100 leagues due East from point A to point B. On normal terrain, they can cover 10 leagues per day, and so the journey would take 10 days. However, their path is crossed by a long marsh which runs exactly South-West to North-East, and walking through the marsh will slow them down. The marsh is 50 leagues wide at all points, and the mid-point of AB is located in the middle of the marsh. A map of the region is shown in the diagram below:

The marsh consists of 5 distinct regions, each 10 leagues across, as shown by the shading in the map. The strip closest to point A is relatively light marsh, and can be crossed at a speed of 9 leagues per day. However, each strip becomes progressively harder to navigate, the speeds going down to 8, 7, 6 and finally 5 leagues per day for the final region of marsh, before it ends and the terrain becomes easier again, with the speed going back to 10 leagues per day.

If Frodo and Sam were to head directly East for point B, they would travel exactly 100 leagues, and the journey would take approximately 13.4738 days. However, this time can be shortened if they deviate from the direct path.

Find the shortest possible time required to travel from point A to B, and give your answer in days, rounded to 10 decimal places.

Answer: 13.1265108586


Let $D(m,n)=\displaystyle\sum_{d\mid m}\sum_{k=1}^n\sigma_0(kd)$ where $d$ runs through all divisors of $m$ and $\sigma_0(n)$ is the number of divisors of $n$.

You are given $D(3!,10^2)=3398$ and $D(4!,10^6)=268882292$.

Find $D(200!,10^{12}) \bmod (10^9 + 7)$.

Answer: 439689828


For every $n \ge 1$ the prime-counting function $\pi(n)$ is equal to the number of primes
not exceeding $n$.

E.g. $\pi(6)=3$ and $\pi(100)=25$.

We say that a sequence of integers $u  = (u_0,\cdots,u_m)$ is a $\pi$ sequence if

-  $u_n \ge 1$ for every $n$

-  $u_{n+1}= \pi(u_n)$

-  $u$ has two or more elements

For $u_0=10$ there are three distinct $\pi$ sequences: $(10,4)$, $(10,4,2)$ and $(10,4,2,1)$.

Let  $c(u)$ be the number of elements of $u$ that are not prime.

Let $p(n,k)$ be the number of $\pi$ sequences $u$  for which $u_0\le n$ and $c(u)=k$.

Let $P(n)$ be the product of all $p(n,k)$ that are larger than $0$.

You are given: $P(10)=3 \times 8 \times 9 \times 3=648$ and $P(100)=31038676032$.

Find $P(10^8)$. Give your answer modulo $1000000007$.

Answer: 172023848


A random generator produces a sequence of symbols drawn from the set {I, V, X, L, C, D, M, #}. Each item in the sequence is determined by selecting one of these symbols at random, independently of the other items in the sequence. At each step, the seven letters are equally likely to be selected, with probability 14% each, but the # symbol only has a 2% chance of selection.

We write down the sequence of letters from left to right as they are generated, and we stop at the first occurrence of the # symbol (without writing it). However, we stipulate that what we have written down must always (when non-empty) be a valid Roman numeral representation in minimal form. If appending the next letter would contravene this then we simply skip it and try again with the next symbol generated.

Please take careful note of About... Roman Numerals for the definitive rules for this problem on what constitutes a "valid Roman numeral representation" and "minimal form". For example, the (only) sequence that represents 49 is XLIX. The subtractive combination IL is invalid because of rule (ii), while XXXXIX is valid but not minimal. The rules do not place any restriction on the number of occurrences of M, so all positive integers have a valid representation. These are the same rules as were used in Problem 89, and members are invited to solve that problem first.

Find the expected value of the number represented by what we have written down when we stop. (If nothing is written down then count that as zero.) Give your answer rounded to 8 places after the decimal point.

Answer: 319.30207833


Peter moves in a hallway with $N + 1$ doors consecutively numbered from $0$ through $N$. All doors are initially closed. Peter starts in front of door $0$, and repeatedly performs the following steps:

- First, he walks a positive square number of doors away from his position.

- Then he walks another, larger square number of doors away from his new position.

- He toggles the door he faces (opens it if closed, closes it if open).

- And finally returns to door $0$.

We call an action any sequence of those steps. Peter never performs the exact same action twice, and makes sure to perform all possible actions that don't bring him past the last door.

Let $F(N)$ be the number of doors that are open after Peter has performed all possible actions. You are given that $F(5) = 1$, $F(100) = 27$, $F(1000) = 233$ and $F(10^6) = 112168$.

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

Answer: 49283233900


Let's call two numbers friend numbers if their representation in base $10$ has at least one common digit.
E.g. $1123$ and $3981$ are friend numbers.

Let $f(n)$ be the number of pairs $(p,q)$ with $1\le p \lt q \lt n$ such that $p$ and $q$ are friend numbers.

$f(100)=1539$.

Find $f(10^{18}) \bmod 1000267129$.

Answer: 819963842


Dave is doing his homework on the balcony and, preparing a presentation about Pythagorean triangles, has just cut out a triangle with side lengths 30cm, 40cm and 50cm from some cardboard, when a gust of wind blows the triangle down into the garden.

Another gust blows a small ant straight onto this triangle. The poor ant is completely disoriented and starts to crawl straight ahead in random direction in order to get back into the grass.

Assuming that all possible positions of the ant within the triangle and all possible directions of moving on are equiprobable, what is the probability that the ant leaves the triangle along its longest side?

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

Answer: 0.3916721504


An integer partition of a number $n$ is a way of writing $n$ as a sum of positive integers. Partitions that differ only by the order of their summands are considered the same.

We call an integer partition special if 1) all its summands are distinct, and 2) all its even summands are also divisible by $4$.
For example, the special partitions of $10$ are: $$10 = 1+4+5=3+7=1+9$$
The number $10$ admits many more integer partitions (a total of $42$), but only those three are special.

Let be $P(n)$ the number of special integer partitions of $n$. You are given that $P(1) = 1$, $P(2) = 0$, $P(3) = 1$, $P(6) = 1$, $P(10)=3$, $P(100) = 37076$ and $P(1000)=3699177285485660336$.

Find $\displaystyle \sum_{i=1}^{10^7} P(i)$. Give the result modulo $10^9+7$.

Answer: 130694090


Consider the natural numbers having at least $5$ prime factors, which don't have to be distinct.
Sorting these numbers by size gives a list which starts with:

- $32=2 \cdot 2 \cdot 2 \cdot 2 \cdot 2$

- $48=2 \cdot 2 \cdot 2 \cdot 2 \cdot 3$

- $64=2 \cdot 2 \cdot 2 \cdot 2 \cdot 2 \cdot 2$

- $72=2 \cdot 2 \cdot 2 \cdot 3 \cdot 3$

- $80=2 \cdot 2 \cdot 2 \cdot 2 \cdot 5$

- $96=2 \cdot 2 \cdot 2 \cdot 2 \cdot 2 \cdot 3$

- $\cdots$

So, for example, the fifth number with at least $5$ prime factors is $80$.

Find the millionth number with at least one million prime factors.
Give your answer modulo $123454321$.

Answer: 108424772


Alice plays the following game, she starts with a list of integers $L$ and on each step she can either:

- remove two elements $a$ and $b$ from $L$ and add $a^b$ to $L$

- or conversely remove an element $c$ from $L$ that can be written as $a^b$, with $a$ and $b$ being two integers such that $a, b > 1$, and add both $a$ and $b$ to $L$

For example starting from the list $L=\{8\}$, Alice can remove $8$ and add $2$ and $3$ resulting in $L=\{2,3\}$ in a first step. Then she can obtain $L=\{9\}$ in a second step.

Note that the same integer is allowed to appear multiple times in the list.

An integer $n>1$ is said to be creative if for any integer $m \gt 1$ Alice can obtain a list that contains $m$ starting from $L=\{n\}$.

Find the sum of all creative integers less than or equal to $10^{12}$.

Answer: 310884668312456458


For two integers $n,e \gt 1$, we define an $(n,e)$-MPS (Mirror Power Sequence) to be an infinite sequence of integers $(a_i)_{i\ge 0}$ such that for all $i\ge 0$, $a_{i+1} = \min(a_i^e,n-a_i^e)$ and $a_i \gt 1$.
Examples of such sequences are the two $(18,2)$-MPS sequences made of alternating $2$ and $4$.

Note that even though such a sequence is uniquely determined by $n,e$ and $a_0$, for most values such a sequence does not exist. For example, no $(n,e)$-MPS exists for $n \lt 6$.

Define $C(n)$ to be the number of $(n,e)$-MPS for some $e$, and $\displaystyle D(N) = \sum_{n=2}^N C(n)$.

You are given that $D(10) = 2$, $D(100) = 21$, $D(1000) = 69$, $D(10^6) = 1303$ and $D(10^{12}) = 1014800$.

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

Answer: 1001133757


Consider the numbers $15$, $16$ and $18$:

$15=3\times 5$ and $3+5=8$.

$16 = 2\times 2\times 2\times 2$ and $2+2+2+2=8$.

$18 = 2\times 3\times 3$ and $2+3+3=8$.

$15$, $16$ and $18$ are the only numbers that have $8$ as sum of the prime factors (counted with multiplicity).

We define $S(k)$ to be the sum of all numbers $n$ where the sum of the prime factors (with multiplicity)  of $n$ is $k$.

Hence $S(8) = 15+16+18 = 49$.

Other examples: $S(1) = 0$, $S(2) = 2$, $S(3) = 3$, $S(5) = 5 + 6 = 11$.

The Fibonacci sequence is $F_1 = 1$, $F_2 = 1$, $F_3 = 2$, $F_4 = 3$, $F_5 = 5$, ....

Find the last nine digits of $\displaystyle\sum_{k=2}^{24}S(F_k)$.

Answer: 634212216


For a set of positive integers $\{a, a+1, a+2, \dots , b\}$, let $C(a,b)$ be the number of non-empty subsets in which the product of all elements is a perfect square.

For example $C(5,10)=3$, since the products of all elements of $\{5, 8, 10\}$, $\{5, 8, 9, 10\}$ and $\{9\}$ are perfect squares, and no other subsets of $\{5, 6, 7, 8, 9, 10\}$ have this property.

You are given that $C(40,55) =15$, and $C(1000,1234) \bmod 1000000007=975523611$.

Find $C(1000000,1234567) \bmod 1000000007$.

Answer: 857810883


A circle $C$ of circumference $c$ centimetres has a smaller circle $S$ of circumference $s$ centimetres lying off-centre within it. Four other distinct circles, which we call "planets", with circumferences $p$, $p$, $q$, $q$ centimetres respectively ($p<q$), are inscribed within $C$ but outside $S$, with each planet touching both $C$ and $S$ tangentially. The planets are permitted to overlap one another, but the boundaries of $S$ and $C$ must be at least 1cm apart at their closest point.

Now suppose that these circles are actually gears with perfectly meshing teeth at a pitch of 1cm. $C$ is an internal gear with teeth on the inside. We require that $c$, $s$, $p$, $q$ are all integers (as they are the numbers of teeth), and we further stipulate that any gear must have at least 5 teeth.

Note that "perfectly meshing" means that as the gears rotate, the ratio between their angular velocities remains constant, and the teeth of one gear perfectly align with the groves of the other gear and vice versa. Only for certain gear sizes and positions will it be possible for $S$ and $C$ each to mesh perfectly with all the planets. Arrangements where not all gears mesh perfectly are not valid.

Define $g(c,s,p,q)$ to be the number of such gear arrangements for given values of $c$, $s$, $p$, $q$: it turns out that this is finite as only certain discrete arrangements are possible satisfying the above conditions. For example, $g(16,5,5,6)=9$.

Here is one such arrangement:

Let $G(n) = \sum_{s+p+q\le n} g(s+p+q,s,p,q)$ where the sum only includes cases with $p<q$, $p\ge 5$, and $s\ge 5$, all integers. You are given that $G(16)=9$ and $G(20)=205$.

Find $G(500)$.

Answer: 1470337306


Gauss famously proved that every positive integer can be expressed as the sum of three triangular numbers (including $0$ as the lowest triangular number). In fact most numbers can be expressed as a sum of three triangular numbers in several ways.

Let $G(n)$ be the number of ways of expressing $n$ as the sum of three triangular numbers, regarding different arrangements of the terms of the sum as distinct.

For example, $G(9) = 7$, as $9$ can be expressed as: $3+3+3$, $0+3+6$, $0+6+3$, $3+0+6$, $3+6+0$, $6+0+3$, $6+3+0$.

You are given $G(1000) = 78$ and $G(10^6) = 2106$.

Find $G(17526 \times 10^9)$.

Answer: 11429712


A riffle shuffle is executed as follows: a deck of cards is split into two equal halves, with the top half taken in the left hand and the bottom half taken in the right hand. Next, the cards are interleaved exactly, with the top card in the right half inserted just after the top card in the left half, the 2nd card in the right half just after the 2nd card in the left half, etc. (Note that this process preserves the location of the top and bottom card of the deck)

Let $s(n)$ be the minimum number of consecutive riffle shuffles needed to restore a deck of size $n$ to its original configuration, where $n$ is a positive even number.

Amazingly, a standard deck of $52$ cards will first return to its original configuration after only $8$ perfect shuffles, so $s(52) = 8$. It can be verified that a deck of $86$ cards will also return to its original configuration after exactly $8$ shuffles, and the sum of all values of $n$ that satisfy $s(n) = 8$ is $412$.

Find the sum of all values of n that satisfy $s(n) = 60$.

Answer: 3010983666182123972


The lambda-calculus is a universal model of computation at the core of functional programming languages. It is based on lambda-terms, a minimal programming language featuring only function definitions, function calls and variables. Lambda-terms are built according to the following rules:

- Any variable $x$ (single letter, from some infinite alphabet) is a lambda-term.

- If $M$ and $N$ are lambda-terms, then $(M N)$ is a lambda-term, called the application of $M$ to $N$.

- If $x$ is a variable and $M$ is a term, then $(\lambda x. M)$ is a lambda-term, called an abstraction. An abstraction defines an anonymous function, taking $x$ as parameter and sending back $M$.

A lambda-term $T$ is said to be closed if for all variables $x$, all occurrences of $x$ within $T$ are contained within some abstraction $(\lambda x. M)$ in $T$. The smallest such abstraction is said to bind the occurrence of the variable $x$. In other words, a lambda-term is closed if all its variables are bound to parameters of enclosing functions definitions. For example, the term $(\lambda x. x)$ is closed, while the term $(\lambda x. (x y))$ is not because $y$ is not bound.

Also, we can rename variables as long as no binding abstraction changes. This means that $(\lambda x. x)$ and $(\lambda y. y)$ should be considered equivalent since we merely renamed a parameter. Two terms equivalent modulo such renaming are called $\alpha$-equivalent. Note that $(\lambda x. (\lambda y. (x y)))$ and $(\lambda x. (\lambda x. (x x)))$ are not $\alpha$-equivalent, since the abstraction binding the first variable was the outer one and becomes the inner one. However, $(\lambda x. (\lambda y. (x y)))$ and $(\lambda y. (\lambda x. (y x)))$ are $\alpha$-equivalent.

The following table regroups the lambda-terms that can be written with at most $15$ symbols, symbols being parenthesis, $\lambda$, dot and variables.

$$\begin{array}{|c|c|c|c|}
\hline
(\lambda x.x) & (\lambda x.(x x)) & (\lambda x.(\lambda y.x)) & (\lambda x.(\lambda y.y)) \\
\hline
(\lambda x.(x (x x))) & (\lambda x.((x x) x)) & (\lambda x.(\lambda y.(x x))) & (\lambda x.(\lambda y.(x y))) \\
\hline
(\lambda x.(\lambda y.(y x))) & (\lambda x.(\lambda y.(y y))) & (\lambda x.(x (\lambda y.x))) & (\lambda x.(x (\lambda y.y))) \\
\hline
(\lambda x.((\lambda y.x) x)) & (\lambda x.((\lambda y.y) x)) & ((\lambda x.x) (\lambda x.x)) & (\lambda x.(x (x (x x)))) \\
\hline
(\lambda x.(x ((x x) x))) & (\lambda x.((x x) (x x))) & (\lambda x.((x (x x)) x)) & (\lambda x.(((x x) x) x)) \\
\hline
\end{array}$$

Let be $\Lambda(n)$ the number of distinct closed lambda-terms that can be written using at most $n$ symbols, where terms that are $\alpha$-equivalent to one another should be counted only once. You are given that $\Lambda(6) = 1$, $\Lambda(9) = 2$, $\Lambda(15) = 20$ and $\Lambda(35) = 3166438$.

Find $\Lambda(2000)$. Give the answer modulo $1\,000\,000\,007$.

Answer: 3679796


An unbiased coin is tossed repeatedly until two consecutive heads are obtained. Suppose these occur on the $(M-1)$th and $M$th toss.

Let $P(n)$ be the probability that $M$ is divisible by $n$. For example, the outcomes HH, HTHH, and THTTHH all count towards $P(2)$, but THH and HTTHH do not.

You are given that $P(2) =\frac 3 5$ and $P(3)=\frac 9  {31}$. Indeed, it can be shown that $P(n)$ is always a rational number.

For a prime $p$ and a fully reduced fraction $\frac a b$, define $Q(\frac a b,p)$ to be the smallest positive $q$ for which $a \equiv b q \pmod{p}$.

For example $Q(P(2), 109) = Q(\frac 3 5, 109) = 66$, because $5 \cdot 66 = 330 \equiv 3 \pmod{109}$ and $66$ is the smallest positive such number.

Similarly $Q(P(3),109) = 46$.

Find $Q(P(10^{18}),1\,000\,000\,009)$.

Answer: 984524441


Answer: 551614306


A binary matrix is a matrix consisting entirely of $0$s and $1$s. Consider the following transformations that can be performed on a binary matrix:

- Swap any two rows

- Swap any two columns

- Flip all elements in a single row ($1$s become $0$s, $0$s become $1$s)

- Flip all elements in a single column

Two binary matrices $A$ and $B$ will be considered equivalent if there is a sequence of such transformations that when applied to $A$ yields $B$. For example, the following two matrices are equivalent:

$A=\begin{pmatrix}
1 & 0 & 1 \\
0 & 0 & 1 \\
0 & 0 & 0 \\
\end{pmatrix} \quad B=\begin{pmatrix}
0 & 0 & 0 \\
1 & 0 & 0 \\
0 & 0 & 1 \\
\end{pmatrix}$
via the sequence of two transformations "Flip all elements in column 3" followed by "Swap rows 1 and 2".

Define $c(n)$ to be the maximum number of $n\times n$ binary matrices that can be found such that no two are equivalent. For example, $c(3)=3$. You are also given that $c(5)=39$ and $c(8)=656108$.

Find $c(20)$, and give your answer modulo $1\,001\,001\,011$.

Answer: 695577663


Consider the set $S$ of all possible products of $n$ positive integers not exceeding $m$, that is

$S=\{ x_1x_2\cdots x_n \mid 1 \le x_1, x_2, \dots, x_n \le m \}$.

Let $F(m,n)$ be the number of the distinct elements of the set $S$.

For example, $F(9, 2) = 36$ and $F(30,2)=308$.

Find $F(30, 10001) \bmod 1\,000\,000\,007$.

Answer: 220196142


A position in chess is an (orientated) arrangement of chess pieces placed on a chessboard of given size. In the following, we consider all positions in which $n$ pawns are placed on a  $n \times n$
board in such a way, that there is a single pawn in every row and every column.

We call such a position an open position, if a rook, starting at the (empty) lower left corner and using only moves towards the right or upwards, can reach the upper right corner without moving onto any field occupied by a pawn.

Let $f(n)$ be the number of open positions for a $n \times n$ chessboard.

For example, $f(3)=2$, illustrated by the two open positions for a $3 \times 3$ chessboard below.

|  |  |  |

You are also given $f(5)=70$.

Find $f(10^8)$ modulo $1\,008\,691\,207$.

Answer: 210286684


Alice and Bob are playing a modified game of Nim called Scatterstone Nim, with Alice going first, alternating turns with Bob. The game begins with an arbitrary set of stone piles with a total number of stones equal to $n$.

During a player's turn, he/she must pick a pile having at least $2$ stones and perform a split operation, dividing the pile into an arbitrary set of $p$ non-empty, arbitrarily-sized piles where $2 \leq p \leq k$ for some fixed constant $k$. For example, a pile of size $4$ can be split into $\{1, 3\}$ or $\{2, 2\}$, or $\{1, 1, 2\}$ if $k = 3$ and in addition $\{1, 1, 1, 1\}$ if $k = 4$.

If no valid move is possible on a given turn, then the other player wins the game.

A winning position is defined as a set of stone piles where a player can ultimately ensure victory no matter what the other player does.

Let $f(n,k)$ be the number of winning positions for Alice on her first turn, given parameters $n$ and $k$. For example, $f(5, 2) = 3$ with winning positions $\{1, 1, 1, 2\}, \{1, 4\}, \{2, 3\}$. In contrast, $f(5, 3) = 5$ with winning positions $\{1, 1, 1, 2\}, \{1, 1, 3\}, \{1, 4\}, \{2, 3\}, \{5\}$.

Let $g(n)$ be the sum of $f(n,k)$ over all $2 \leq k \leq n$. For example, $g(7)=66$ and $g(10)=291$.

Find $g(200) \bmod (10^9 + 7)$.

Answer: 626616617


Given a set, $L$, of unique lines, let $M(L)$ be the number of lines in the set and let $S(L)$ be the sum over every line of the number of times that line is crossed by another line in the set.  For example, two sets of three lines are shown below:

In both cases $M(L)$ is $3$ and $S(L)$ is $6$: each of the three lines is crossed by two other lines. Note that even if the lines cross at a single point, all of the separate crossings of lines are counted.

Consider points $(T_{2k-1}, T_{2k})$, for integer $k \ge 1$, generated in the following way:

$S_0 	=  	290797$

$S_{n+1} 	=  	S_n^2 \bmod 50515093$

$T_n 	=  	(S_n \bmod 2000) - 1000$

For example, the first three points are: $(527, 144)$, $(-488, 732)$, $(-454, -947)$. Given the first $n$ points generated in this manner, let $L_n$ be the set of unique lines that can be formed by joining each point with every other point, the lines being extended indefinitely in both directions.  We can then define $M(L_n)$ and $S(L_n)$ as described above.

For example, $M(L_3) = 3$ and $S(L_3) = 6$. Also $M(L_{100}) = 4948$ and $S(L_{100}) = 24477690$.

Find $S(L_{2500})$.

Answer: 9669182880384


Let $(p_1 p_2 \ldots p_k)$ denote the permutation of the set ${1, ..., k}$ that maps $p_i\mapsto i$. Define the length of the permutation to be $k$; note that the empty permutation $()$ has length zero.

Define an occurrence of a permutation $p=(p_1 p_2 \cdots p_k)$ in a permutation $P=(P_1 P_2 \cdots P_n)$ to be a sequence $1\leq t_1 \lt t_2 \lt \cdots \lt t_k \leq n$ such that $p_i \lt p_j$ if and only if $P_{t_i} \lt P_{t_j}$ for all $i,j \in \{1, \dots, k\}$.

For example, $(1243)$ occurs twice in the permutation $(314625)$: once as the 1st, 3rd, 4th and 6th elements $(3\,\,46\,\,5)$, and once as the 2nd, 3rd, 4th and 6th elements $(\,\,146\,\,5)$.

Let $f(n, m)$ be the number of permutations $P$ of length at most $n$ such that there is no occurrence of the permutation $1243$ in $P$ and there are at most $m$ occurrences of the permutation $21$ in $P$.

For example, $f(2,0) = 3$, with the permutations $()$, $(1)$, $(1,2)$ but not $(2,1)$.

You are also given that $f(4, 5) = 32$ and $f(10, 25) = 294\,400$.

Find $f(10^{18}, 40)$ modulo $1\,000\,000\,007$.

Answer: 869588692


For an integer $n$, we define the square prime factors of $n$ to be the primes whose square divides $n$. For example, the square prime factors of $1500=2^2 \times 3 \times 5^3$ are $2$ and $5$.

Let $C_k(N)$ be the number of integers between $1$ and $N$ inclusive with exactly $k$ square prime factors. You are given some values of $C_k(N)$ in the table below.

$$\begin{array}{|c|c|c|c|c|c|c|}
\hline

& k = 0 & k = 1 & k = 2 & k = 3 & k = 4 & k = 5 \\
\hline
N=10 & 7 & 3 & 0 & 0 & 0 & 0 \\
\hline
N=10^2 & 61 & 36 & 3 & 0 & 0 & 0 \\
\hline
N=10^3 & 608 & 343 & 48 & 1 & 0 & 0 \\
\hline
N=10^4 & 6083 & 3363 & 533 & 21 & 0 & 0 \\
\hline
N=10^5 & 60794 & 33562 & 5345 & 297 & 2 & 0 \\
\hline
N=10^6 & 607926 & 335438 & 53358 & 3218 & 60 & 0 \\
\hline
N=10^7 & 6079291 & 3353956 & 533140 & 32777 & 834 & 2 \\
\hline
N=10^8 & 60792694 & 33539196 & 5329747 & 329028 & 9257 & 78 \\
\hline
\end{array}$$

Find the product of all non-zero $C_k(10^{16})$. Give the result reduced modulo $1\,000\,000\,007$.

Answer: 728378714


For an integer $n$, we define the square prime factors of $n$ to be the primes whose square divides $n$. For example, the square prime factors of $1500=2^2 \times 3 \times 5^3$ are $2$ and $5$.

Let $C_k(N)$ be the number of integers between $1$ and $N$ inclusive with exactly $k$ square prime factors. It can be shown that with growing $N$ the ratio $\frac{C_k(N)}{N}$ gets arbitrarily close to a constant $c_{k}^{\infty}$, as suggested by the table below.

$$\begin{array}{|c|c|c|c|c|c|}
\hline
& k = 0 & k = 1 & k = 2 & k = 3 & k = 4 \\
\hline
C_k(10) & 7 & 3 & 0 & 0 & 0 \\
\hline
C_k(10^2) & 61 & 36 & 3 & 0 & 0 \\
\hline
C_k(10^3) & 608 & 343 & 48 & 1 & 0 \\
\hline
C_k(10^4) & 6083 & 3363 & 533 & 21 & 0 \\
\hline
C_k(10^5) & 60794 & 33562 & 5345 & 297 & 2 \\
\hline
C_k(10^6) & 607926 & 335438 & 53358 & 3218 & 60 \\
\hline
C_k(10^7) & 6079291 & 3353956 & 533140 & 32777 & 834 \\
\hline
C_k(10^8) & 60792694 & 33539196 & 5329747 &  329028 & 9257 \\
\hline
C_k(10^9) & 607927124 & 335389706 & 53294365 & 3291791 & 95821 \\
\hline
c_k^{\infty} & \frac{6}{\pi^2} & 3.3539\times 10^{-1} & 5.3293\times 10^{-2} & 3.2921\times 10^{-3} & 9.7046\times 10^{-5}\\
\hline
\end{array}$$
Find $c_{7}^{\infty}$. Give the result in scientific notation rounded to $5$ significant digits, using a $e$ to separate mantissa and exponent. E.g. if the answer were $0.000123456789$, then the answer format would be $1.2346\mathrm e{-4}$.

Answer: 1.0012e-10


Define $F(n)$ to be the number of integers $x≤n$ that can be written in the form $x=a^2b^3$, where $a$ and $b$ are integers not necessarily different and both greater than 1.

For example, $32=2^2\times 2^3$  and $72=3^2\times 2^3$ are the only two integers less than $100$ that can be written in this form. Hence, $F(100)=2$.

Further you are given $F(2\times 10^4)=130$ and $F(3\times 10^6)=2014$.

Find $F(9\times 10^{18})$.

Answer: 4019680944


Let $A_q(n)$ be the number of subsets, $B$, of the set $\{1, 2, ..., q \cdot n\}$ that satisfy two conditions:

1) $B$ has exactly $n$ elements;

2) the sum of the elements of $B$ is divisible by $n$.

E.g. $A_2(5)=52$ and $A_3(5)=603$.

Let $S_q(L)$ be $\sum A_q(p)$ where the sum is taken over all primes $p \le L$.

E.g. $S_2(10)=554$, $S_2(100)$ mod $1\,000\,000\,009=100433628$ and
$S_3(100)$ mod $1\,000\,000\,009=855618282$.

Find $S_2(10^8)+S_3(10^8)$. Give your answer modulo $1\,000\,000\,009$.

Answer: 689294705


Consider writing a natural number as product of powers of natural numbers with given exponents, additionally requiring different base numbers for each power.

For example, $256$ can be written as a product of a square and a fourth power in three ways such that the base numbers are different.

That is, $256=1^2\times 4^4=4^2\times 2^4=16^2\times 1^4$

Though $4^2$ and $2^4$ are both equal, we are concerned only about the base numbers in this problem. Note that permutations are not considered distinct, for example $16^2\times 1^4$ and $1^4 \times 16^2$ are considered to be the same.

Similarly, $10!$ can be written as a product of one natural number, two squares and three cubes in two ways ($10!=42\times5^2\times4^2\times3^3\times2^3\times1^3=21\times5^2\times2^2\times4^3\times3^3\times1^3$) whereas $20!$ can be given the same representation in $41680$ ways.

Let $F(n)$ denote the number of ways in which $n$ can be written as a product of one natural number, two squares, three cubes and four fourth powers.

You are given that $F(25!)=4933$, $F(100!) \bmod 1\,000\,000\,007=693\,952\,493$,

and $F(1\,000!) \bmod 1\,000\,000\,007=6\,364\,496$.

Find $F(1\,000\,000!) \bmod 1\,000\,000\,007$.

Answer: 888316


Given any positive integer $n$, we can construct a new integer by inserting plus signs between some of the digits of the base $B$ representation of $n$, and then carrying out the additions.

For example, from $n=123_{10}$  ($n$ in base $10$) we can construct the four base $10$ integers $123_{10}$,  $1+23=24_{10}$, $12+3=15_{10}$ and $1+2+3=6_{10}$.

Let $f(n,B)$ be the smallest number of steps needed to arrive at a single-digit number in base $B$. For example, $f(7,10)=0$ and $f(123,10)=1$.

Let $g(n,B_1,B_2)$ be the sum of the positive integers $i$ not exceeding $n$ such that $f(i,B_1)=f(i,B_2)$.

You are given $g(100,10,3)=3302$.

Find $g(10^7,10,3)$.

Answer: 49000634845039


Let $P_{a,b}$ denote a path in a $a\times b$ lattice grid with following properties:

- The path begins at $(0,0)$ and ends at $(a,b)$.

- The path consists only of unit moves upwards or to the right; that is the coordinates are increasing with every move.

Denote $A(P_{a,b})$ to be the area under the path. For the example of a $P_{4,3}$ path given below, the area equals $6$.

Define $G(P_{a,b},k)=k^{A(P_{a,b})}$. Let $C(a,b,k)$ equal the sum of $G(P_{a,b},k)$ over all valid paths in a $a\times b$ lattice grid.

You are given that

- $C(2,2,1)=6$

- $C(2,2,2)=35$

- $C(10,10,1)=184\,756$

- $C(15,10,3) \equiv 880\,419\,838 \mod 1\,000\,000\,007$

- $C(10\,000,10\,000,4) \equiv 395\,913\,804 \mod 1\,000\,000\,007$

Calculate $\displaystyle\sum_{k=1}^7 C(10^k+k, 10^k+k,k)$. Give your answer modulo $1\,000\,000\,007$

Answer: 18423394


A multiplicative function $f(x)$ is a function over positive integers satisfying $f(1)=1$ and $f(a b)=f(a) f(b)$ for any two coprime positive integers $a$ and $b$.

For integer $k$ let $f_k(n)$ be a multiplicative function additionally satisfying $f_k(p^e)=p^k$ for any prime $p$ and any integer $e>0$.

For example, $f_1(2)=2$, $f_1(4)=2$, $f_1(18)=6$ and $f_2(18)=36$.

Let $\displaystyle S_k(n)=\sum_{i=1}^{n} f_k(i)$.
For example, $S_1(10)=41$, $S_1(100)=3512$, $S_2(100)=208090$, $S_1(10000)=35252550$ and $\displaystyle \sum_{k=1}^{3} S_k(10^{8}) \equiv 338787512 \pmod{ 1\,000\,000\,007}$.

Find $\displaystyle \sum_{k=1}^{50} S_k(10^{12}) \bmod 1\,000\,000\,007$.

Answer: 797866893


Bob plays a single-player game of chance using two standard 6-sided dice and twelve cards numbered 1 to 12. When the game starts, all cards are placed face up on a table.

Each turn, Bob rolls both dice, getting numbers $x$ and $y$ respectively, each in the range 1,...,6. He must choose amongst three options: turn over card $x$, card $y$, or card $x+y$. (If the chosen card is already face down, it is turned to face up, and vice versa.)

If Bob manages to have all twelve cards face down at the same time, he wins.

Alice plays a similar game, except that instead of dice she uses two fair coins, counting heads as 2 and tails as 1, and that she uses four cards instead of twelve. Alice finds that, with the optimal strategy for her game, the expected number of turns taken until she wins is approximately 5.673651.

Assuming that Bob plays with an optimal strategy, what is the expected number of turns taken until he wins? Give your answer rounded to 6 places after the decimal point.

Answer: 50.317928


Consider a row of $n$ dice all showing 1.

First turn every second die,$ (2,4,6,\ldots)$, so that the number showing is increased by 1. Then turn every third die. The sixth die will now show a 3. Then turn every fourth die and so on until every $n$th die (only the last die) is turned. If the die to be turned is showing a 6 then it is changed to show a 1.

Let $f(n)$ be the number of dice that are showing a 1 when the process finishes. You are given $f(100)=2$ and $f(10^8) = 69$.

Find $f(10^{36})$.

Answer: 793525366


Let $f(n)$ be the largest prime factor of $n$ and $\displaystyle F(n) = \sum_{i=2}^n f(i)$.

For example $F(10)=32$, $F(100)=1915$ and $F(10000)=10118280$.

Find $F(201820182018)$. Give your answer modulus $10^9$.

Answer: 631499044


Two positive integers $a$ and $b$ are $2$-friendly when $\gcd(a,b) = 2^t, t \gt 0$. For example, $24$ and $40$ are $2$-friendly because $\gcd(24,40) = 8 = 2^3$ while $24$ and $36$ are not because $\gcd(24,36) = 12 = 2^2\cdot 3$ is not a power of $2$.

Let $f(n)$ be the number of pairs, $(p,q)$, of positive integers with $1\le p\lt q\le n$ such that $p$ and $q$ are $2$-friendly. You are given $f(10^2) = 1031$ and $f(10^6) = 321418433$ modulo $1\,000\,000\,007$.

Find $f(10^{11})$ modulo $1\,000\,000\,007$.

Answer: 968274154


Sam and Tom are trying a game of (partially) covering a given line segment of length $L$ by taking turns in placing unit squares onto the line segment.

As illustrated below, the squares may be positioned in two different ways, either "straight" by placing the midpoints of two opposite sides on the line segment, or "diagonal" by placing two opposite corners on the line segment. Newly placed squares may touch other squares, but are not allowed to overlap any other square laid down before.

The player who is able to place the last unit square onto the line segment wins.

With Sam starting each game by placing the first square, they quickly realise that Sam can easily win every time by placing the first square in the middle of the line segment, making the game boring.

Therefore they decide to randomise Sam's first move, by first tossing a fair coin to determine whether the square will be placed straight or diagonal onto the line segment and then choosing the actual position on the line segment randomly with all possible positions being equally likely. Sam's gain of the game is defined to be 0 if he loses the game and $L$ if he wins. Assuming optimal play of both players after Sam's initial move, you can see that Sam's expected gain, called $e(L)$, is only dependent on the length of the line segment.

For example, if $L=2$, Sam will win with a probability of $1$, so $e(2)= 2$.

Choosing $L=4$, the winning probability will be $0.33333333$ for the straight case and $0.22654092$ for the diagonal case, leading to $e(4)=1.11974851$ (rounded to $8$ digits after the decimal point each).

Being interested in the optimal value of $L$ for Sam, let's define $f(a,b)$ to be the maximum of $e(L)$ for some $L \in [a,b]$.

You are given $f(2,10)=2.61969775$, being reached for $L= 7.82842712$, and $f(10,20)=
5.99374121$ (rounded to $8$ digits each).

Find $f(200,500)$, rounded to $8$ digits after the decimal point.

Answer: 20.11208767


On planet J, a year lasts for $D$ days. Holidays are defined by the two following rules.

- At the beginning of the reign of the current Emperor, his birthday is declared a holiday from that year onwards.

- If both the day before and after a day $d$ are holidays, then $d$ also becomes a holiday.

Initially there are no holidays. Let $E(D)$ be the expected number of Emperors to reign before all the days of the year are holidays, assuming that their birthdays are independent and uniformly distributed throughout the $D$ days of the year.

You are given $E(2)=1$, $E(5)=31/6$, $E(365)\approx 1174.3501$.

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

Answer: 48894.2174


Let $n$ be a natural number and  $p_1^{\alpha_1}\cdot p_2^{\alpha_2}\cdots p_k^{\alpha_k}$ its prime factorisation.

Define the Liouville function $\lambda(n)$ as $\lambda(n) = (-1)^{\sum\limits_{i=1}^{k}\alpha_i}$.

(i.e. $-1$ if the sum of the exponents $\alpha_i$ is odd and $1$ if the sum of the exponents is even. )

Let $S(n,L,H)$  be the sum $\lambda(d) \cdot d$ over all divisors $d$ of $n$ for which $L \leq d \leq H$.

You are given:

- $S(10! , 100, 1000) = 1457$

- $S(15!,  10^3, 10^5) = -107974$

- $S(30!,10^8, 10^{12}) = 9766732243224$.

Find $S(70!,10^{20}, 10^{60})$ and give your answer modulo $1\,000\,000\,007$.

Answer: 845218467


It is possible to find positive integers $A$ and $B$ such that given any triangular number, $T_n$, then $AT_n +B$ is always a triangular number. We define $F_3(N)$ to be the sum of $(A+B)$ over all such possible pairs $(A,B)$ with $\max(A,B)\le N$. For example $F_3(100) = 184$.

Polygonal numbers are generalisations of triangular numbers. Polygonal numbers with parameter $k$ we call $k$-gonal numbers. The formula for the $n$th $k$-gonal number is $\frac 12n\big(n(k-2)+4-k\big)$ where $n \ge 1$. For example when $k = 3$ we get $\frac 12n(n+1)$ the formula for triangular numbers.

The statement above is true for pentagonal, heptagonal and in fact any $k$-gonal number with $k$ odd. For example when $k=5$ we get the pentagonal numbers and we can find positive integers $A$ and $B$ such that given any pentagonal number, $P_n$, then $AP_n+B$ is always a pentagonal number. We define $F_5(N)$ to be the sum of $(A+B)$ over all such possible pairs $(A,B)$ with $\max(A,B)\le N$.

Similarly we define $F_k(N)$ for odd $k$. You are given $\sum_{k} F_k(10^3) = 14993$ where the sum is over all odd $k = 3,5,7,\ldots$.

Find $\sum_{k} F_k(10^{12})$ where the sum is over all odd $k = 3,5,7,\ldots$

Answer: 563132994232918611


For some fixed $\rho \in [0, 1]$, we begin a sum $s$ at $0$ and repeatedly apply a process: With probability $\rho$, we add $1$ to $s$, otherwise we add $2$ to $s$.

The process ends when either $s$ is a perfect square or $s$ exceeds $10^{18}$, whichever occurs first. For example, if $s$ goes through $0, 2, 3, 5, 7, 9$, the process ends at $s=9$, and two squares $1$ and $4$ were skipped over.

Let $f(\rho)$ be the expected number of perfect squares skipped over when the process finishes.

It can be shown that the power series for $f(\rho)$ is $\sum_{k=0}^\infty a_k \rho^k$ for a suitable (unique) choice of coefficients $a_k$. Some of the first few coefficients are $a_0=1$, $a_1=0$, $a_5=-18$, $a_{10}=45176$.

Let $F(n) = \sum_{k=0}^n a_k$. You are given that $F(10) = 53964$ and $F(50) \equiv 842418857 \pmod{10^9}$.

Find $F(1000)$, and give your answer modulo $10^9$.

Answer: 301483197