Since Project Euler problems are now fair game for questions I have a question of my own.
A certain problem* states:
For a positive integer n, let σ2(n) be the sum of the squares of its divisors. For example,
σ2(10) = 1 + 4 + 25 + 100 = 130.
Find the sum of all n, 0 < n < 64,000,000 such that σ2(n) is a perfect square.
This Mathematica code takes something like an hour to run on a modern machine:
Sum[If[IntegerQ @ Sqrt @ DivisorSigma[2, i], i, 0], {i, 64*^6 - 1}] ~Monitor~ i // Timing
The similarly naive PARI/GP code takes a minute or two:
sum(n=1,64*10^6,issquare(sigma(n,2))*n)
Is there some way to make the Mathematica code fast, or otherwise solve the problem quickly in Mathematica?
Using a faster perfect square testa faster perfect square test helps quite a bit but it is still far from the PARI/GP performance.
Compilation does not seem possible as numbers exceed the maximum machine-size integer.
(*To foil search engines please do not mention the number of the Project Euler problem related to this question. Thanks.)