Project Euler Lab - Problem 940

#940 - Two-Dimensional Recurrence

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

The Fibonacci sequence \((f_i)\) is the unique sequence such that

  • \(f_0=0\)
  • \(f_1=1\)
  • \(f_{i+1}=f_i+f_{i-1}\)

Similarly, there is a unique function \(A(m,n)\) such that

  • \(A(0,0)=0\)
  • \(A(0,1)=1\)
  • \(A(m+1,n)=A(m,n+1)+A(m,n)\)
  • \(A(m+1,n+1)=2A(m+1,n)+A(m,n)\)

Define \(S(k)=\displaystyle\sum_{i=2}^k\sum_{j=2}^k A(f_i,f_j)\). For example \[ \begin{align} S(3)&=A(1,1)+A(1,2)+A(2,1)+A(2,2)\\ &=2+5+7+16\\ &=30 \end{align} \]You are also given \(S(5)=10396\).

Find \(S(50)\), giving your answer modulo \(1123581313\).

This problem is taken from Project Euler, Problem 940.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=940. Published Saturday, 12th April 2025, 05:00 pm. Solved by 657 members at time of mirroring.

Why this is useful

Numerical Computing. Matrix methods and linear-recurrence acceleration are the machinery behind covariance work, PCA, and lattice/transition models (Phases 4, 5, 8).

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.