Project Euler Lab - Problem 943

#943 - Self Describing Sequences

● ResearchOfficial difficulty: 90%RecurrencesTier D - conceptual / notebook executionNot viewed
↖ Euler Lab

Given two unequal positive integers \(a\) and \(b\), we define a self-describing sequence consisting of alternating runs of \(a\)s and \(b\)s. The first element is \(a\) and the sequence of run lengths is the original sequence.

For \(a=2, b=3\), the sequence is: \[2, 2, 3, 3, 2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2, 2, 3, 3, 3, 2, 2, 2, 3, 3, 3,...\] The sequence begins with two \(2\)s and two \(3\)s, then three \(2\)s and three \(3\)s, so the run lengths \(2, 2, 3, 3, ...\) are given by the original sequence.

Let \(T(a, b, N)\) be the sum of the first \(N\) elements of the sequence. You are given \(T(2,3,10) = 25\), \(T(4,2,10^4) = 30004\), \(T(5,8,10^6) = 6499871\).

Find \(\sum T(a, b, 22332223332233)\) for \(2 \le a \le 223\), \(2 \le b \le 223\) and \(a \neq b\). Give your answer modulo \(2233222333\).

This problem is taken from Project Euler, Problem 943.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=943. Published Sunday, 4th May 2025, 02:00 am. Solved by 105 members at time of mirroring.

Why this is useful

Mathematical Foundation. Exact integer reasoning and algorithmic efficiency. Foundational rigour and computational discipline rather than a direct trading application.

We classify relevance honestly - not every Euler problem is a trading application.

Learning mode

Pick how much scaffolding you want. Your choice is remembered per problem.

Scratchpad

Mathematical notes, formulas, pseudocode, hypotheses, complexity notes. Saved automatically with your progress.

Python workbench

Tier D - conceptual / notebook execution
Too heavy for browser Pyodide at original scale: the browser is used for planning, small cases and reasoning; full scale runs in a local notebook.

Real Python (Pyodide) in a sandboxed Web Worker - no network, no filesystem, no DOM access. Ctrl/Cmd+Enter runs. Escape leaves the editor. Stop terminates the worker.

Python runtime not loaded (it boots on first run - a one-time local load).

Check your answer

Answers are checked against a salted hash held in a separate file - not printed in this page. This prevents accidental spoilers; it is not cryptographic protection (see the build notes).

Progressive hints

Confidence

Low confidence schedules this problem for spaced review, even if you solved it.

Reference solution

Spoiler
The complete original explanation (interpretation, naive approach, insight, proof, complexity, Python implementation, tests, common mistakes, alternatives) is hidden and lazy-loaded. Reveal it only after a meaningful attempt - the struggle is where the learning happens.