Legendre's three-square theorem

转载 2015年11月19日 17:13:42
From Wikipedia, the free encyclopedia

In mathematicsLegendre's three-square theorem states that a natural number can be represented as the sum of three squares of integers

n = x^2 + y^2 + z^2

if and only if n is not of the form n = 4^a(8b + 7) for integers a and b.

The first numbers that cannot be expressed as the sum of three squares (i.e. numbers that can be expressed as n = 4^a(8b + 7)) are

7, 15, 23, 28, 31, 39, 47, 55, 60, 63, 71 ... (sequence A004215 in OEIS).


Pierre de Fermat gave a criterion for numbers of the form 3a+1 to be a sum of 3 squares essentially equivalent to Legendre's theorem, but did not provide a proof. N. Beguelin noticed in 1774[1] that every positive integer which is neither of the form 8n + 7, nor of the form 4n, is the sum of three squares, but did not provide a satisfactory proof.[2] In 1796 Gauss proved his Eureka theorem that every positive integer n is the sum of 3 triangular numbers; this is trivially equivalent to the fact that 8n+3 is a sum of 3 squares. In 1797 or 1798 A.-M. Legendre obtains the first proof of his 3 square theorem.[3] In 1813, A. L. Cauchynotes[4] that Legendre's theorem is equivalent to the statement in the introduction above. Previously, in 1801, C. F. Gauss had obtained a more general result,[5] containing Legendre theorem of 1797-8 as a corollary. In particular, Gauss counts the number of solutions of the expression of an integer as a sum of three squares, and this is a generalisation of yet another result of Legendre,[6] whose proof is incomplete. This last fact appears to be the reason for later incorrect claims according to which Legendre's proof of the three-square theorem was defective and had to be completed by Gauss.[7]

With Lagrange's four-square theorem and the two-square theorem of Girard, Fermat and Euler, the Waring's problem for k = 2 is entirely solved.


The "only if" of the theorem is simply because modulo 8, every square is congruent to 0, 1 or 4. There are several proofs of the converse. One of them is due to J. P. G. L. Dirichlet in 1850, and has become classical.[8] It requires three main lemmas:

Relationship to the four-square theorem[edit]

This theorem can be used to prove Lagrange's four-square theorem, which states that all natural numbers can be written as a sum of four squares. Gauss[9] pointed out that the four squares theorem follows easily from the fact that any positive integer that is 1 or 2 mod 4 is a sum of 3 squares, because any positive integer not divisible by 4 can be reduced to this form by subtracting 0 or 1 from it. However, proving the three-square theorem is considerably more difficult than a direct proof of the four-square theorem that does not use the three-square theorem.

[LeetCode] 279. Perfect Squares 解题报告

Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, ...
  • a921122
  • a921122
  • 2017年02月19日 03:04
  • 188

UVa 11342 - Three-square

題目:給定一個數字,判斷能否拆成三個平方數的和。 分析:數論,枚舉。直接枚舉其中的兩個數字,然後判斷剩下的數字是不是平方數即可。 說明:判斷是不是平方數可以直接利用開方函數,結果賦值給整數和浮點,...
  • mobius_strip
  • mobius_strip
  • 2015年12月17日 15:33
  • 416

Fermat's little theorem(费马小定理)

If p is prime, then for every a >= 1 and a 如果p是质数,那么对于所有的 大于1,小于p的 a,都有 a 的 p-1 次方 除以 p 的余数为1。 这个定理...
  • topasstem8
  • topasstem8
  • 2013年09月24日 08:47
  • 2129

棋盘覆盖和Hall's marriage theorem

今天整理了一下自己电脑里存了一年的所有PDF,然后发现好像有很多很多很多都没有看,所以今天一整天就翻这些PDF去了。发现了这么一本杂志不知道什么时候下下来的叫做《Recreational Mathem...
  • magicnumber
  • magicnumber
  • 2015年02月05日 21:26
  • 1562

zoj 1738 - Lagrange's Four-Square Theorem

题目:四平方定理,输出一个数可以表示成不超过四个平方数和的表示方法数。 分析:dp,完全背包。整数拆分用背包,可用一维分步计算,也可统一写成二维。              状态:设f(i,j,k...
  • mobius_strip
  • mobius_strip
  • 2014年10月01日 18:03
  • 1073

POJ 3641 Pseudoprime numbers 【快速幂】

Pseudoprime numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 878...
  • lututu123
  • lututu123
  • 2016年07月28日 08:47
  • 141

Mercer's Theorem的证明

[由于还没有完全学会PHP和HTML,暂时先用新浪博客写一部分文档,之后等自己建出来个人网站后,在将博客移动至个人网站。今天算是人生以来第一个博客吧!] 在学习Kernel和RKHS的时...
  • zlx562998710
  • zlx562998710
  • 2016年02月21日 22:48
  • 952

AtCoder Regular Contest 076 F - Exhausted (Hall's marriage theorem 或 贪心)

转化后的题意就是:有N个人,1 ~ M号座位,第i个人愿意坐的座位是[1,Li]或 [Ri,M]。设这个二分图最大匹配是X,然后输出N - X,即问最少有几个人意愿得不到满足。 思路: 在...
  • kalilili
  • kalilili
  • 2017年06月25日 00:17
  • 380

poj 3511 Fermat's Christmas Theorem 筛素数

//poj 3511 //sep9 #include using namespace std; const int max_prime_num = 1000010; const int max_n ...
  • sepNINE
  • sepNINE
  • 2016年12月11日 18:15
  • 186

CodeForces 199A Hexadecimal's theorem

题意:给出一个数字,判断是否能通过三个Fibonacci Number(可重复)求和得到,若可以,输出这三个数,若不可以,按要求输出字符串 链接:http://codeforces.com/pr...
  • luminous11
  • luminous11
  • 2015年02月27日 20:15
  • 378
您举报文章:Legendre's three-square theorem