Project Euler Lab - Problem 130

#130 - Composites with Prime Repunit Property

● AppliedOfficial difficulty: 21%DivisibilityTier B - browser, with the efficient algorithmNot viewed
↖ Euler Lab

A number consisting entirely of ones is called a repunit. We shall define \(R(k)\) to be a repunit of length \(k\); for example, \(R(6) = 111111\).

Given that \(n\) is a positive integer and \(\gcd(n, 10) = 1\), it can be shown that there always exists a value, \(k\), for which \(R(k)\) is divisible by \(n\), and let \(A(n)\) be the least such value of \(k\); for example, \(A(7) = 6\) and \(A(41) = 5\).

You are given that for all primes, \(p \gt 5\), that \(p - 1\) is divisible by \(A(p)\). For example, when \(p = 41\), \(A(41) = 5\), and \(40\) is divisible by \(5\).

However, there are rare composite values for which this is also true; the first five examples being \(91\), \(259\), \(451\), \(481\), and \(703\).

Find the sum of the first twenty-five composite values of \(n\) for which \(\gcd(n, 10) = 1\) and \(n - 1\) is divisible by \(A(n)\).

This problem is taken from Project Euler, Problem 130.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=130. Published Friday, 27th October 2006, 06:00 pm. Solved by 6,892 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 B - browser, with the efficient algorithm
Runs in the browser only with the intended efficient algorithm; a naive loop will hit the timeout.

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.