Next: Sums of More Squares
Up: Sums of Two Squares
Previous: Which Numbers are the
Suppose is a prime of the form . There is a construction of
Legendre of and that is explained on pages 120-121 of
Davenport. I'm unconvinced that it is any more efficient than the
following naive algorithm: compute
for
until it's an integer. This takes at most steps. Here's
a simple PARI program which implements this algorithm.
{sumoftwosquares(n) =
local(y);
for(x=1,floor(sqrt(n)),
y=sqrt(n-x^2);
if(y-floor(y)==0, return([x,floor(y)]))
);
error(n," is not a sum of two squares.")
}
William A Stein
2001-10-31