用a[i,j] (1 ≤ i,j ≤ 2n+1) 表示格中第i行j列的值,則如下賦值是一個解
a[i,j] = [(n + i - j) % (2n+1)] * (2n+1) + [(i+j-(n+2)) % (2n+1)] + 1
%表示取餘運算 例如 7%5=2 -2%5=3 5%5=0 18%5=3
證明: 我們需要證明如下3點:
1) 1 ≤ a[i,j] ≤ (2n+1)^2
2) a[i,j]兩兩不同
3) Sigma(j=1 to 2n+1) a[i,j] //每行
= Sigma(i=1 to 2n+1) a[i,j] //每列
= Sigma(i=1 to 2n+1) a[i,i] //對角線1
= Sigma(i=1 to 2n+1) a[i,(2n+1)-i+1] //對角線2
= 某一定值
1) 1 ≤ [(n + i - j) % (2n+1)] * (2n+1) + [(i+j-(n+2)) % (2n+1)] + 1
<= (2n+1-1)*(2n+1) + (2n+1-1) + 1
= 2n(2n+1) + 2n + 1
= (2n+1)^2
2) 假若有1到2n+1之間的4個整數i1,j1, i2,j2滿足
a[i1,j1] = a[i2,j2]
則
[(n + i1 - j1) % (2n+1)] * (2n+1) + [(i1 + j1-(n+2)) % (2n+1)] + 1
= [(n + i2 - j2) % (2n+1)] * (2n+1) + [(i2 + j2-(n+2)) % (2n+1)] + 1
因此
[(i1-i2) - (j1-j2)) % (2n+1)] * (2n+1) + [((i1-i2) + (j1-j2)) % (2n+1)] = 0
令 Δi=i1-i2, Δj=j1-j2,
則 [( Δi - Δj) % (2n+1)] * (2n+1) + [(Δi + Δj) % (2n+1)] = 0
因 (Δi - Δj) % (2n+1) ≥ 0, (Δi + Δj) % (2n+1) ≥ 0, 必有
(Δi - Δj) % (2n+1) = 0
(Δi + Δj) % (2n+1) = 0
因此 Δi - Δj = u*(2n+1)
Δi + Δj = v*(2n+1)
u,v為整數
Δi = (u+v)*(2n+1)/2
Δj = (v-u)*(2n+1)/2
因2n+1是奇數,(u+v)和(u-v)必為偶數,即
Δi = s*(2n+1)
Δj = t*(2n+1)
s,t為整數
又因 1 ≤ i1, i2 ≤ 2n+1
-2n = (1-(2n+1) ≤ Δi = i1 - i2 ≤ (2n+1-1) = 2n
必有 Δi=0
同理 Δj=0
即i1=i2, j1=j2
3) 令N = Sigma(i=1 to (2n+1)^2)/(2n+1) = (2n+1) * (2n^2 + 2n + 1), 注意N是隻依賴於n的定值
Sigma(j=1 to 2n+1) a[i,j]
= Sigma(j=1 to 2n+1) {[(n + i - j) % (2n+1)] * (2n+1) + [(i+j-(n+2)) % (2n+1)] + 1}
= (2n+1) * Sigma(j=1 to 2n+1) [(n + i - j) % (2n+1)] + Sigma(j=1 to 2n+1) [(i+j-(n+2)) % (2n+1)] + (2n+1)
= (2n+1) * (0+1+...+2n) + (0+1+...+2n) + (2n+1)
= (2n+1) * 2n * (2n+1)/2 + 2n * (2n+1)/2 + (2n+1)
= (2n+1) * (2n^2+n + n + 1)
= (2n+1) * (2n^2 + 2n + 1)
= N
同樣可得
Sigma(i=1 to 2n+1) a[i,j]
=(2n+1) * (2n^2 + 2n + 1)
= N
Sigma(i=1 to 2n+1) a[i,i]
= Sigma(i=1 to 2n+1) {[(n + i - i) % (2n+1)] * (2n+1) + [(i+i-(n+2)) % (2n+1)] + 1}
= Sigma (i=1 to 2n+1) [n*(2n+1)] + Sigma (i=1 to 2n+1) [(2i-(n+2)) % (2n+1)] + (2n+1)
= (2n+1)^2 * n + (0+1+...+2n) + (2n+1)
// 注意: 當i從1到2n+1遍曆時, 2i(從而2i-(n+2))除以2n+1的餘數遍曆0到2n
= (2n+1)^2 * n + 2n*(2n+1)/2 + (2n+1)
= (2n+1)(2n^2 + 2n + 1)
= N
Sigma(i=1 to 2n+1) a[i,(2n+1)-i+1]
= Sigma(i=1 to 2n+1) {[(n + i - (2n+1)+i-1) % (2n+1)] * (2n+1) + [(i+(2n+1)-i+1-(n+2)) % (2n+1)] + 1}
= Sigma(i=1 to 2n+1) [(2i - (n+1)-1) % (2n+1)] * (2n+1) + Sigma(i=1 to 2n+1)[((2n+1)+1-(n+2)) % (2n+1)] + (2n+1)
= (0+1+...+2n)*(2n+1) + (2n+1)*n + (2n+1)
= (2n+1)^2*2n/2 + (2n+1)*n + 1
= (2n+1)*(2n^2+n + n + 1)
= (2n+1)*(2n^2+2n+1)
= N