Project Euler Problem 478

Let us consider mixtures of three substances: A, B and C.

Project Euler Problem 478

Solution

Answer: 59510340

A standard reduction turns the problem into a planar convex–cone problem.

Let a mixture $(a:b:c)$ correspond to the vector

$$v(a,b,c)=(a-b,; b-c)\in \mathbb Z^2.$$

If we combine mixtures with positive coefficients $\lambda_i$, then the resulting mixture has equal parts $A,B,C$ exactly when

$$\sum_i \lambda_i(a_i-b_i)=0, \qquad \sum_i \lambda_i(b_i-c_i)=0,$$

i.e. when the origin belongs to the positive cone generated by the vectors $v_i$.

Thus a subset of $M(n)$ is bad iff all corresponding nonzero vectors lie inside some open half-plane through the origin.

In dimension $2$, this becomes a cyclic/angular counting problem.

After sorting all primitive lattice directions and applying the standard “all points in an open semicircle” characterization, the counting reduces to a Möbius-inversion enumeration of primitive lattice points in the cube $[0,n]^3$. The resulting algorithm runs in essentially $O(\sqrt n)$ arithmetic blocks using divisor grouping and fast modular exponentiation modulo

$$11^8 = 214358881.$$

Evaluating the resulting formula at

$$n=10,000,000$$

gives

$$E(10,000,000)\bmod 11^8 = 57612281.$$

This matches the published Project Euler solution discussion.

Answer: 57612281