Project Euler Lab - Problem 620

#620 - Planetary Gears

● ResearchOfficial difficulty: 98%CountingTier C - reduced scale in browser; full scale in notebookNot viewed
↖ Euler Lab

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:

Example 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)\).

This problem is taken from Project Euler, Problem 620.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=620. Published Sunday, 11th February 2018, 01:00 am. Solved by 196 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.