What is the fastest algorithm that represents a prime as the sum of two squares?

I could use two loops to check all combinations of two integers that are less than pprime, but this is very inefficient. Is there a better algorithm to solve this problem? Any ideas?

Where p mod 4 = 1.

Thank,

+3
source share
3 answers

. :

  • [1..trunc(sqrt (p))].
  • sqrt (p-i ^ 2) , . , .
  • i.

? p, , , , .

+2

, 4n + 1.

, . Mathematica:

P[p_] := Reduce[-p + x^2 + y^2 == 0, {x, y}, Integers]

:

Finding solutions for the first few primes p that are 1 or 2 (mod 4).

P /@ {2, 5, 13, 17, 29, 37, 41, 53, 61}

enter image description here

0
source

All Articles