USING: math math.functions math.primes project-euler.common sequences sets ; IN: project-euler.087 ! https://projecteuler.net/index.php?section=problems&id=87 ! 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? > O((n / log n)^(13/12)) ! ! When n = 50,000,000, the first equation is approximately 10 ! million and the second is approximately 2 billion. :: prime-triples ( n -- answer ) n sqrt primes-upto :> primes primes 2 n prime-powers-less-than :> primes^2 primes 3 n prime-powers-less-than :> primes^3 primes 4 n prime-powers-less-than :> primes^4 primes^2 primes^3 [ + ] cartesian-map concat primes^4 [ + ] cartesian-map concat [ n <= ] filter members length ; PRIVATE> :: euler087 ( -- answer ) 50,000,000 prime-triples ; SOLUTION: euler087