Project Euler Problem 615

Consider the natural numbers having at least 5 prime factors, which don't have to be distinct.

Project Euler Problem 615

Solution

Answer: 108424772

Let

$$n = 2^{1000000-k}\cdot m,$$

where $m$ contains exactly $k$ prime factors greater than $2$.

Then every such number can be written as

$$n = 2^{1000000}\prod_i \frac{p_i}{2}.$$

So the ordering is determined entirely by the comparatively small product of factors $p_i/2$. Empirically, only the last $27$ factors need to vary from $2$, which reduces the search to generating the smallest candidates with exactly $27$ variable prime factors.

Using a priority queue (best-first search) over these candidates gives the millionth element efficiently. The resulting reduced candidate is

$$11622919700480.$$

Multiplying back by the missing factor $2^{1000000-27}$ modulo $123454321$ yields

$$108424772.$$

This matches the known efficient search strategy for the problem.

Answer: 108424772