Project Euler Lab - Problem 988

#988 - Non-attacking Frogs

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

Frogs can be placed on the real number line at integer locations. Given coprime positive integers \((a,b)\), each frog has the ability to make jumps of distances \(a\) or \(b\) in the positive direction.

Two frogs placed at \(m\) and \(n\), \(m<n\), are attacking if the frog at \(m\) can hop to \(n\) with some series of jumps. For example if \((a,b)=(3,5)\), frogs placed at \(0\) and \(11\) are attacking as the former can make two jumps of \(3\) and one jump of \(5\) to reach \(11\). However, frogs placed at \(4\) and \(11\) are non-attacking.

A non-attacking configuration is a placement of any number of frogs such that:

  • one frog is placed at \(0\);
  • all other frogs are placed at distinct positive integers;
  • no two frogs are attacking.

Define \(F(a,b)\) to be sum of the integer locations of every frog, summing over all non-attacking configurations. For example if \((a,b)=(3,5)\) there are seven non-attacking configurations: \[\{0\}\quad\quad\{0,1\}\quad\quad\{0,2\}\quad\quad\{0,4\}\quad\quad\{0,7\}\quad\quad\{0,1,2\}\quad\quad\{0,2,4\} \]giving \(F(3,5)=23\).

You are also given \(F(5,13)=16336\).

Find \(F(19,53)\).

This problem is taken from Project Euler, Problem 988.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=988. Published Sunday, 15th March 2026, 07:00 am. Solved by 169 members at time of mirroring.

Why this is useful

Algorithmic Development. Optimal substructure and state-space reasoning are exactly how American-option pricing and optimal execution are solved (Phases 13, 16).

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.