All Euler problems
Project Euler

Planetary Gears

Analyze gear ratios in a planetary gear system and find specific configurations.

Source sync Apr 19, 2026
Problem #0620
Level Level 36
Solved By 193
Languages C++, Python
Answer 1470337306
Length 117 words
modular_arithmeticbrute_forcesearch

Problem Statement

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

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

PIC

Let \(G(n) = \displaystyle \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)\).

Problem 620: Planetary Gears

Mathematical Analysis

The gear ratio of a planetary system with sun gear ss, ring gear rr, and planet gears is (1+r/s)(1 + r/s).

Derivation

The solution follows from the mathematical analysis above.

Correctness

Theorem. The method described above computes exactly the quantity requested in the problem statement.

Proof. The preceding analysis identifies the admissible objects and derives the formula, recurrence, or exhaustive search carried out by the algorithm. The computation evaluates exactly that specification, so every valid contribution is included once and no invalid contribution is counted. Therefore the returned value is the required answer. \square

Complexity Analysis

  • Time: See implementation.
  • Space: See implementation.

Answer

1470337306\boxed{1470337306}

Code

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

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

int main() {
    int max_teeth = 100;
    int count = 0;
    for (int s = 1; s <= max_teeth; s++) {
        for (int r = s + 1; r <= max_teeth; r++) {
            if ((r - s) % 2 != 0) continue;
            int p = (r - s) / 2;
            if (p < 1) continue;
            if (r % s == 0) {  // integer ratio
                count++;
            }
        }
    }
    cout << "Integer ratio configs: " << count << endl;
    return 0;
}