## Project Euler 87: Investigating numbers that can be expressed as the sum of a prime square, cube, and fourth power

#### Project Euler 87 Problem Description

The smallest number expressible as the sum of a prime square, prime cube, and prime fourth power is 28. In fact, there are exactly four numbers below fifty that can be expressed in such a way:

28 = 2^{2} + 2^{3} + 2^{4}

33 = 3^{2} + 2^{3} + 2^{4}

49 = 5^{2} + 2^{3} + 2^{4}

47 = 2^{2} + 3^{3} + 2^{4}

How many numbers below fifty million can be expressed as the sum of a prime square, prime cube, and prime fourth power?

#### Analysis

This is a problem that brute force solves so quickly and easily that much more investigation is hardly warranted. It’s not obvious that any other approach would produce a much faster solution.

Basically, this routine generates a list of prime numbers and considers candidates for the square root, cube root and fourth root of the limit. Then we iterate over the lists and calculate unique numbers below 50,000,000 as p_{2}^{2} + p_{3}^{3} + p_{4}^{4}, where p_{2}, p_{3},and p_{4} are prime numbers. The length of the set is the how many discrete sets fit the criteria.

#### Project Euler 87 Solution

Runs < 0.360 seconds in Python 2.7.```
from Euler import prime_sieve as sieve
from itertools import product
P = set()
for a,b,c in product(sieve(7072), sieve(369), sieve(85)):
q = a*a + b**3 + c**4
if q >= 50000000: break
P.add(q)
print len(P)
```

Use this link to get the Project Euler 87 Solution Python 2.7 source.#### Answer

Slowly swipe from either end beginning with the white vertical bar to get an idea of the starting or ending digits. For less drama, just double click the answer area. The distance between the two bars will give you an idea of the magnitude. Touch devices can tap and hold the center of the box between the two bars and choose*define*to reveal the answer.

#### Afterthoughts

- Runs for 1,409,343 iterations.

*Project Euler 87 Solution last updated*

from Euler import prime_sieve as sieve

How to get above line work. No module found for me.

https://blog.dreamshire.com/common-functions-routines-project-euler/#prime_sieve

You can find all the useful functions we use on this page.