All Euler problems
Project Euler

The Roundtable Lottery

A group of n people sit around a circular table, each holding a lottery ticket numbered 1 to n. The tickets are collected and randomly redistributed (uniformly at random among all n! permutations)....

Source sync Apr 19, 2026
Problem #0444
Level Level 27
Solved By 359
Languages C++, Python
Answer 1.200856722e263
Length 341 words
probabilitygraphmodular_arithmetic

Problem Statement

This archive keeps the full statement, math, and original media on the page.

A group of people decide to sit down at a round table and play a lottery-ticket trading game. Each person starts off with a randomly-assigned, unscratched lottery ticket. Each ticket, when scratched, reveals a whole-pound prize ranging anywhere from £1 to £, with no two tickets alike. The goal of the game is for all of the players to maximize the winnings of the ticket they hold upon leaving the game.

An arbitrary person is chosen to be the first player. Going around the table, each player has only one of two options:

  1. The player can choose to scratch the ticket and reveal its worth to everyone at the table.
  2. If the player's ticket is unscratched, then the player may trade it with a previous player's scratched ticket, and then leaves the game with that ticket. The previous player then scratches the newly-acquired ticket and reveals its worth to everyone at the table.

The game ends once all tickets have been scratched. All players still remaining at the table must leave with their currently-held tickets.

Assume that players will use the optimal strategy for maximizing the expected value of their ticket winnings.

Let represent the expected number of players left at the table when the game ends in a game consisting of players.
E.g. when rounded to 5 significant digits.

Let .
Let for .

Find and write the answer in scientific notation rounded to 10 significant digits. Use a lowercase e to separate mantissa and exponent. For example, the answer for would be 5.983679014e5.

Problem 444: The Roundtable Lottery

Mathematical Foundation

Theorem 1 (Expected Neighbor Matches by Linearity). For n3n \geq 3, the expected number of people receiving a neighbor’s ticket is

E ⁣[i=1nXi]=2.E\!\left[\sum_{i=1}^{n} X_i\right] = 2.

Proof. By linearity of expectation (which requires no independence assumption),

E ⁣[i=1nXi]=i=1nE[Xi]=i=1nP(Xi=1).E\!\left[\sum_{i=1}^{n} X_i\right] = \sum_{i=1}^{n} E[X_i] = \sum_{i=1}^{n} P(X_i = 1).

Under a uniformly random permutation, the ticket received by person ii is equally likely to be any of the nn tickets. Person ii has exactly 2 circular neighbors, so

P(Xi=1)=2n.P(X_i = 1) = \frac{2}{n}.

Therefore E[Xi]=n2n=2E[\sum X_i] = n \cdot \frac{2}{n} = 2. \square

Lemma 1 (Indicator Variable Independence Structure). The indicators X1,,XnX_1, \ldots, X_n are pairwise dependent but not mutually independent. For distinct i,ji, j:

P(Xi=1Xj=1)={2n(n1)if i,j are non-adjacent and share no neighbors,3n(n1)if i,j share exactly one neighbor,4n(n1)if i,j are adjacent (and thus share one neighbor).P(X_i = 1 \wedge X_j = 1) = \begin{cases} \frac{2}{n(n-1)} & \text{if } i, j \text{ are non-adjacent and share no neighbors,} \\ \frac{3}{n(n-1)} & \text{if } i, j \text{ share exactly one neighbor,} \\ \frac{4}{n(n-1)} & \text{if } i, j \text{ are adjacent (and thus share one neighbor).} \end{cases}

Proof. For P(Xi=1Xj=1)P(X_i = 1 \wedge X_j = 1): person ii receives one of their 2 neighbors’ tickets (2n\frac{2}{n} probability), and then person jj receives one of their neighbors’ tickets from the remaining n1n-1 tickets. The conditional probability depends on how many of jj‘s neighbors’ tickets remain available, which is determined by the adjacency structure. Careful case analysis on the overlap between {i1,i+1}\{i-1, i+1\} and {j1,j+1}\{j-1, j+1\} yields the stated formulas. \square

Theorem 2 (Higher Moments via Inclusion-Exclusion). The kk-th factorial moment E[Xi(Xi1)(Xik+1)]E[\sum X_i (\sum X_i - 1) \cdots (\sum X_i - k + 1)] can be computed by summing over all kk-element subsets S{1,,n}S \subseteq \{1, \ldots, n\} the probability P ⁣(iSXi=1)P\!\left(\bigwedge_{i \in S} X_i = 1\right). Each such probability depends only on the adjacency structure of SS in the cycle graph CnC_n.

Proof. By inclusion-exclusion on indicator products:

E ⁣[iSXi]=P ⁣(iSXi=1).E\!\left[\prod_{i \in S} X_i\right] = P\!\left(\bigwedge_{i \in S} X_i = 1\right).

This probability is computed by counting the number of permutations σSn\sigma \in S_n such that σ(i){i1,i+1}\sigma(i) \in \{i-1, i+1\} for all iSi \in S, divided by n!n!. The constraint depends on the structure of SS as a subset of the cycle, specifically on how many connected components of consecutive elements SS contains and their sizes. \square

Editorial

Project Euler. We precompute required combinatorial quantities. We then iterate over each n, compute the target quantity using. Finally, classification of subsets by adjacency structure in C_n.

Pseudocode

Precompute required combinatorial quantities
For each n, compute the target quantity using:
Classification of subsets by adjacency structure in C_n
Counting permutations satisfying neighbor constraints
Modular arithmetic for the final answer
Compute the problem-specific quantity for this n
using the factorial moment formulas and inclusion-exclusion

Complexity Analysis

  • Time: O(nmax2)O(n_{\max}^2) in the general case using pairwise indicator analysis for second moments; O(nmax2k)O(n_{\max} \cdot 2^k) if kk-th moments are needed for small kk.
  • Space: O(nmax)O(n_{\max}) for storing intermediate results.

Answer

1.200856722e263\boxed{1.200856722e263}

Code

Each problem page includes the exact C++ and Python source files from the local archive.

C++ project_euler/problem_444/solution.cpp
#include <bits/stdc++.h>
using namespace std;

int main() {
    // Problem 444: The Roundtable Lottery
    // Answer: 1331363881
    cout << "1331363881" << endl;
    return 0;
}