Project Euler Lab - Problem 159

#159 - Digital Root Sums of Factorisations

● AdvancedOfficial difficulty: 37%PolynomialsTier C - reduced scale in browser; full scale in notebookNot viewed
↖ Euler Lab

A composite number can be factored many different ways. For instance, not including multiplication by one, \(24\) can be factored in \(7\) distinct ways:

\[\begin{align} 24 &= 2 \times 2 \times 2 \times 3\\ 24 &= 2 \times 3 \times 4\\ 24 &= 2 \times 2 \times 6\\ 24 &= 4 \times 6\\ 24 &= 3 \times 8\\ 24 &= 2 \times 12\\ 24 &= 24 \end{align}\]

Recall that the digital root of a number, in base \(10\), is found by adding together the digits of that number, and repeating that process until a number is arrived at that is less than \(10\). Thus the digital root of \(467\) is \(8\).

We shall call a Digital Root Sum (DRS) the sum of the digital roots of the individual factors of our number.
The chart below demonstrates all of the DRS values for \(24\).

FactorisationDigital Root Sum
\(2 \times 2 \times 2 \times 3\)\(9\)
\(2 \times 3 \times 4\)\(9\)
\(2 \times 2 \times 6\)\(10\)
\(4 \times 6\)\(10\)
\(3 \times 8\)\(11\)
\(2 \times 12\)\(5\)
\(24\)\(6\)

The maximum Digital Root Sum of \(24\) is \(11\).
The function \(\operatorname{mdrs}(n)\) gives the maximum Digital Root Sum of \(n\). So \(\operatorname{mdrs}(24)=11\).
Find \(\sum \operatorname{mdrs}(n)\) for \(1 \lt n \lt 1\,000\,000\).

This problem is taken from Project Euler, Problem 159.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=159. Published Saturday, 30th June 2007, 02:00 pm. Solved by 3,888 members at time of mirroring.

Why this is useful

Mathematical Foundation. Exact counting underlies discrete pricing lattices, scenario enumeration, and combinatorial probability (Phase 7).

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 C - reduced scale in browser; full scale in notebook
Browser runs a reduced, clearly-labelled educational scale; the original scale is provided 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.