I need a fast algorithm to calculate solutions to $x^2+y^2+z^2=d^2$ for $d>1000$.
I tried Pythagorean quadruple (Alternate parametrization approach) for $d<400$ and it isn't that fast.
UPDATE
def EfficientDivisors(n):
factors = []
i = 2
while (i < sqrt(n)):
if (n%i == 0):
factors.append(i)
if (i != (n/i)):
factors.append(n//i)
i += 1
return factors
#alternative parameterization: a and b are both even
def fncTest4(d):
c = 0
nSolutionNumber = 0
for a in range(2, d, 2):
l = a//2
for b in range(2, d, 2):
m = b//2
nTemp1 = l ** 2 + m ** 2
factors = EfficientDivisors(nTemp1)
for n in factors:
if n ** 2 < nTemp1:
nTemp2 = (nTemp1 + n ** 2) // n
if d == nTemp2:
c = d - 2 * n
nSolutionNumber += 1
print(nSolutionNumber, ":", a, b, c, d)
break
fncTest4(2000) # 4 minutes