将两个方格的总和表示为素数的最快算法是什么?

Cha*_*han 3 algorithm math number-theory

我可以使用两个循环来检查小于p素数的两个整数的所有组合,但效率非常低.有没有更好的算法来解决这个问题?任何的想法?

哪里p mod 4 = 1.

谢谢,

小智 5

您可以尝试使用Hermite-Serret算法.

您还可以在此math.se页面上找到一个很好的算法列表:https://math.stackexchange.com/questions/5877/efficiently-finding-two-squares-which-sum-to-a-prime

特别参见Robin Chapman的回答:https://math.stackexchange.com/questions/5877/efficiently-finding-two-squares-which-sum-to-a-prime/5883#5883