Skip to main content

Euler’s E228: Primality Testing and Factoring via Sums of Squares

  • Conference paper
  • First Online:
Research in History and Philosophy of Mathematics (CSHPM 2016)

Abstract

How can you decide if a number is the sum of two squares? Euler began with the dumbest possible algorithm imaginable: Take the number, subtract a square, and check if the remainder is a square. If not, repeat, repeat, repeat. But Euler, being Euler, found a way of converting all those subtractions into additions. Then he did several things to speed up the computation even more. He applied this to 1,000,009, and—in less than a page—found that there are two ways to express this as a sum of squares. Hence, by earlier work in E228, it is not a prime. Amusingly, when he later described how to prepare a table of primes “ad millionem et ultra” (E467), he included this number as prime. So he then felt obliged to write another paper, E699 (1797), using another refinement of his method, to show that 1,000,009 is not prime.

The problem of distinguishing prime numbers from composite numbers and of resolving the latter into their prime factors is known to be one of the most important and useful in arithmetic

C. F. Gauss, Disquisitiones Arithmeticae, §329

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Institutional subscriptions

Notes

  1. 1.

    This paper, “On numbers which are the sum of two squares,” was read to the Berlin Academy on March 20, 1749 and published in the Novi commentarii academiae scientiarum Petropolitanae, 4, 1758, pp. 3–40. We cite Euler’s papers using their Eneström numbers. This one is E228.

  2. 2.

    There are many proofs. See, e.g., Goldman 1998 (who gives three proofs), Wagon 1990, Zagier 1990, and Jameson 2010.

  3. 3.

    Upon its founding in 1703, the official name of the town was “Sankt Pieter Burch.” From 1724 to 1941 it was “Sanktpeterburg,” but Euler and Goldbach used the Latin form “Petropoli” in their initial letters. For simplicity, we follow the editors of the EG Corr [p. 95] and use simply “Petersburg,” with an infixical “s” that was never used in Russian.

  4. 4.

    For biographical information about Goldbach and his relationship with Euler, see the EG Corr, pp. 3–31.

  5. 5.

    This is a letter number 34 in the new Euler-Goldbach correspondence, Leonhardi Euleri commercium epistolicum cum Christians Goldbach, volume IV.A.4 of Euler’s Opera Omnia, which is in two parts. The first has the correspondence in the original languages, the second has English translations. There is also a useful introduction and an abundance of explanatory notes. The work is edited by Franz Lemmermeyer and Martin Mattmüller and was published by Springer in 2015. These volumes are designated EG Corr here. Sometimes when a letter is cited by number, we omit “EG Corr.”

  6. 6.

    In E26 (1738) Euler “observed after thinking about this for many days” that the fifth Fermat number, \(2^{2^{5} } + 1 = 4\,294\,967\,297\), is not prime because it is divisible by 641. Although he does not give any clue about how he discovered this fact he noted that it can “be seen at once by anyone who cares to check.”

    In E134 (1750), §32, Euler noted that the only trial divisors that he needed to consider were of the form 64n + 1. See Sandifer 2015.

  7. 7.

    The 48 “Observatio Domino Petri de Fermat” are scattered through the 1770 Diophantus, where they occur in print for the first time. The Latin originals have been reprinted in the Œuvers de Fermat, volume 1 (1891), pp. 291–342. French translations are in volume 3 (1896), pp. 241–274.

  8. 8.

    Euler is a bit confused here for he referred to this as the penultimate letter. The penultimate letter, XLVI, is the note, in English dated June 19, 1658, whereby Digby conveys Fermat’s letter to Wallis further requesting that he pass it on to Brouncker.

  9. 9.

    Fermat had a factorization method that bears some similarities with Euler’s, but Euler could not have known about it because it was not published until the nineteenth century by Charles Henry, a librarian, history of mathematics specialist, and co-editor of the Œuvers de Fermat. For a translation and explanation, see Chabert 1999, pp. 264–266. Curiously, Fermat’s method is better known today than Euler’s. See Ore 1948, pp. 56–58 and Burton 1976, pp. 94–97.

  10. 10.

    We know from Euler’s unpublished Catalogus librorum meorum in his “Notebook VI” that he owned a copy of Johann Gottlob Krüger’s Gedancken von der Algebra, nebst den Primzahlen von 1 biß 10000000 (1746) [EG Corr, p. 1071, n. 7]. The title has a misprint; the last prime listed is 100,999. Euler had a copy of this at least by 1760, for he alluded to it in E283 (1764). Even earlier, Euler wrote to Goldbach (April 18 (29), 1741, no 36) that he planned to present him with a copy of Frans van Schooten’s Exercitationum mathematicarum libri quinque (1657) which contains, pp. 393–403, a list of the prime numbers up to 10,000: Syllabus numerorum primorum, qui continentur in decem prioribus chiliadibus. Euler notes that he has copied out the prime numbers of the form 4n + 1 up to 3000. It is not known if Euler had access to a factor table; for history see Bullynck 2010.

  11. 11.

    While I have no information that Euler had access to it, a table of the squares of all numbers up to 100,000 had been published, viz.: Johann-Hiob Ludolf, Tetragonometria tabularia, Quâ Per Tabulas Quadratorum a Radice Quadrata I. Usque Ad I00000, Leipzig: Groschian, 1690. [other editions were published in 1709 and 1712]. See Denis Roegel, A reconstruction of Ludolf’s Tetragonometria tabularia (1690), Technical report, LORIA, Nancy, 2013. Even if Euler did not have such a table, he certainly knew the 22 possible last two digits for a square.

  12. 12.

    The editors of the EG Corr, p. 40, note that Diophantus knew how, from the factors 5 and 13, to represent 65 as the sum of two squares.

  13. 13.

    In the first column 177 is a typo for 176.

References

  • Bullynck, Maarten (2010) Factor tables 1657–1817, with notes on the birth of number theory. Rev. Histoire Math., 16, 133–216.

    MathSciNet  MATH  Google Scholar 

  • Burton, David M (1976) Elementary number theory. Boston: Allyn and Bacon.

    MATH  Google Scholar 

  • Calinger, Ronald S. (2016) Leonhard Euler: Mathematical Genius in the Enlightenment. Princeton.

    MATH  Google Scholar 

  • Chabert, Jean-Luc (1999) A History of Algorithms. From the Pebble to the Microchip. Springer.

    Book  MATH  Google Scholar 

  • E26. Euler, L., Observationes de theoremate quodam Fermatiano aliisque ad numeros primos spectantibus (Observations on a theorem of Fermat and others on looking at prime numbers). Commentarii academiae scientiarum Petropolitanae, 6, 1738, 103–107. Reprinted Opera Omnia, Series 1, Volume 2, 1–5. There are two English translation on the Euler Archive, one by Jordan Bell, the other by David Zhao.

    Google Scholar 

  • E134, Euler, L., Theoremata circa divisores numerorum (Theorems on divisors of numbers). Novi commentarii academiae scientiarum Petropolitanae, 1, 1750, 20–48. Reprinted Opera Omnia, Series 1, Volume 2, 62–85. English translation on the Euler Archive by David Zhao.

    Google Scholar 

  • E228. Euler, L., De numeris, qui sunt aggregata duorum quadratorum (On numbers which are the sum of two squares). Novi commentarii academiae scientiarum Petropolitanae, 4, 1758, 3–40. Reprinted Opera Omnia, Series 1, Volume 2, 295–327. The original publication of E228 and an English translation by Paul Bialek are available on the eulerarchive.maa.org.

    Google Scholar 

  • E241. Euler, L., Demonstratio theorematis Fermatiani omnem numerum primum formae 4n + 1 esse summam duorum quadratorum (Proof of a theorem of Fermat that every number of the form 4n + 1 can be given as the sum of two squares), Novi commentarii academiae scientiarum Petropolitanae, 5, 1760, 3–13. Opera Omnia: Series, Series 1, Volume 2, 328–337

    Google Scholar 

  • E283. Euler, L., De numeris primis valde magnis (On very large prime numbers). Novi commentarii academiae scientiarum Petropolitanae, 9, 1764, 99–153. Reprinted Opera Omnia, Series 1, Volume 3, 1–45.

    Google Scholar 

  • E467. Euler, L., De tabula numerorum primorum usque ad millionem et ultra continuanda, in qua simul omnium numerorum non primorum minimi divisores exprimantur (On the table of prime numbers continued up to one million and beyond, in which at once all the non-prime numbers are expressed by their smallest divisors) Novi commentarii academiae scientiarum Petropolitanae, 19, 1775, 132–183 Reprinted Opera Omnia, Series 1, Volume 3, 359–404.

    Google Scholar 

  • E699. Euler, L., Utrum hic numerus 1000009 sit primus necne inquiritur (An inquiry into whether or not 1000009 is a prime number). Nova acta academiae scientarum imperialis Petropolitinae, 10, 1797, 63–73. Reprinted Opera Omnia, Series 1, Volume 4, 245–254. An English translation by Jordan Bell is on the Euler Archive.

    Google Scholar 

  • EG Corr. Leonhardi Euleri Commercium Epistolicum cum Christiano Goldbach. 2015. Opera Omnia IVA4, two volumes. Lemmermeyer, Franz and Mattmüller, Martin (editors). The letters are in Latin, German, and one in French, with English translation, and with abundant annotations by the editors.

    Google Scholar 

  • Goldman, Jay R. (1998) The Queen of Mathematics. A Historically Motivated Guide to Number Theory, Wellesley, MA; A. K. Peters.

    Google Scholar 

  • Heath, Thomas L. (1910) Diophantus of Alexandria. A Study in the History of Greek Algebra. The first edition was published by Cambridge University Press in 1885. We cite the second edition of 1910 as republished by Dover in 1964.

    Google Scholar 

  • Jameson, G. J. O (2010) Two squares and four squares: the simplest proof of all? The Mathematical Gazette, vol. 94, no. 529, 119–123.

    Article  Google Scholar 

  • McKee, James (1996) Turning Euler’s Factoring Method into a Factoring Algorithm. Bulletin of the London Mathematical Society 28 (volume 4); 351–355. An algorithm is presented which, given a positive integer n, will either factor n or prove it to be prime. The algorithm takes O(n 1∕3 + ε) steps.

    Google Scholar 

  • Ore, Oystein (1948) Number Theory and Its History, McGraw-Hill. See pp. 59–64.

    Google Scholar 

  • Riesel, Hans (1985) Prime Numbers and Computer Methods for Factorization. Birkhäuser. Discusses Euler’s Factoring Method on pp. 158–159, but the techniques are somewhat different than Euler’s.

    Google Scholar 

  • Sandifer, C. Edward (2015) Factoring F 5, pp. 41–44 in How Euler Did Even More. MAA.

    Google Scholar 

  • Weil, André (1984) Number Theory. An approach through history from Hammurabi to Legendre. Springer. J. J. Burckhardt has prepared Euler’s work on number theory: A concordance for A. Weyl’s Number Theory Historia Mathematica, 13 (1986), 28–35. This is very useful, for it links Eneström numbers (with page numbers in Euler’s Opera Omnia) and page numbers in Weil.

    Google Scholar 

  • Wagon, Stan (1990) The Euclidean algorithm strikes again. The American Mathematical Monthly, 97, 125–129.

    Article  MathSciNet  MATH  Google Scholar 

  • Wertheim, Gustav (1887) Elemente der Zahlentheorie. Teubner. See pp. 295–299.

    Google Scholar 

  • Zagier, D. (1990) A One-Sentence Proof That Every Prime p ≡ 1(mod 4) is a Sum of Two Squares. The American Mathematical Monthly, 97, 144.

    Article  MATH  Google Scholar 

Download references

Acknowledgements

Bill Dunham, Florence Fasanelli, Stacy Langton, Jim Tattersall, Steven Weintraub, and two referees all deserve credit for the many suggestions they have made which have improved this paper.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to V. Rickey .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2017 Springer International Publishing Switzerland

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Rickey, V. (2017). Euler’s E228: Primality Testing and Factoring via Sums of Squares. In: Zack, M., Schlimm, D. (eds) Research in History and Philosophy of Mathematics. CSHPM 2016. Proceedings of the Canadian Society for History and Philosophy of Mathematics/La Société Canadienne d’Histoire et de Philosophie des Mathématiques. Birkhäuser, Cham. https://doi.org/10.1007/978-3-319-64551-3_7

Download citation

Publish with us

Policies and ethics