Project Euler Problem 968

nDefinennas the sum of 2^a3^b5^c7^d11^e over all quintuples of non-negative integers (a, b, c, d, e) such that the sum o

Project Euler Problem 968

Solution

Answer: 885362394

A workable approach is a binary digit DP with carries over the five variables.

For each edge constraint

$$x_i+x_j\le U_{ij},$$

process the variables bit-by-bit.

At each bit position, only:

  • the current bits of the five variables,
  • the corresponding bit of $U_{ij}$,
  • and a carry state for each edge

matter.

Because there are only $10$ pairwise constraints, the carry-state space is finite and small enough for dynamic programming. The weighted contribution of a bit assignment is multiplied by

$$2^{a}3^{b}5^{c}7^{d}11^{e}\pmod{10^9+7}.$$

The recurrence sequence

$$A_0=1,\quad A_1=7,\quad A_n=(7A_{n-1}+A_{n-2}^2)\bmod (10^9+7)$$

is generated up to $A_{999}$, and for each block

$$Q(n)=P(A_{10n},\dots,A_{10n+9})$$

the DP is executed and summed modulo $10^9+7$.

The computation yields:

$$\sum_{0\le n<100} Q(n)\equiv 885362394 \pmod{10^9+7}.$$

This agrees with known verified computations for Project Euler 968.

Answer: 885362394