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 = 22 + 23 + 24
33 = 32 + 23 + 24
49 = 52 + 23 + 24
47 = 22 + 33 + 24
How many numbers below fifty million can be expressed as the sum of a prime square, prime cube, and prime fourth power?
%integer_sqrt %pow %cartesian_product %echo %prime_list p87()-> prime_list() ! {all_below,integer_sqrt(50000000),self()}, Primes=receive {primes_below,_,V}->V end, Powers=lists:map(fun(X)-> lists:filter(fun(N)->N<50000000 end,lists:map(fun(Y)->pow(Y,X) end, Primes)) end, [2,3,4]), Ans=length(lists:usort( lists:filter(fun(N)->N<50000000 end,lists:map(fun lists:sum/1, cartesian_product(Powers))))), io:format("~w~n",[Ans]).