Prime Power Triples¶

First, we'll generate all the primes below $\sqrt{50000000} \approx 7071$ - since $7072^2 > 50000000$, we clearly don't need any larger primes.

In [1]:
limit = 50000000
primes = prime_range(isqrt(limit))

After this, it's just a matter of iterating through all these primes repeatedly to find triples $p^2 + q^3 + r^4 < 50000000$. For each term, we iterate from smallest to largest prime - that way, if we encounter a sum (or even just an individual power) greater than 50000000, we don't have to check any following prime (since the sum will also be greater than 50000000), so we can break early.

In [2]:
values = set()
for r in primes:
    if r^4 >= limit:
        break
        
    for q in primes:
        if q^3 + r^4 >= limit:
            break
            
        for p in primes:
            n = p^2 + q^3 + r^4
            if n >= limit:
                break
                
            values.add(n)
In [3]:
len(values)
Out[3]:
1097343

Relevant sequences¶

  • Prime power triples: A134657

Copyright (C) 2025 filifa¶

This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license and the BSD Zero Clause license.