Magic constant
Writing again the numbers in squares, once noticed such a thing. If you enter numbers from 1 to n 2 in columns from left to right, you always get a magic constant when adding numbers along any main diagonal, here you can see it:
M 3 :
1 4 7
2 5 8
3 6 9
M 4 :
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
According to the formula:
M 3 = n * (n 2 + 1) / 2 = 3 * (3 * 3 + 1) / 2 = 30/2 = 15
M 4 = n * (n 2 + 1) / 2 = 4 * (4 * 4 + 1) / 2 = 68/2 = 34
On the diagonals (bold above):
M 3 = 1 + 5 + 9 = 15
M 4 = 1 + 6 + 11 + 16 = 34
Unlike the formula, the diagonals are able to give an answer what happens. Consider the numbers on the diagonals:
M 3 = 1 + 5 + 9
M 4 = 1 + 6 + 11 + 16
Rewrite it differently:
M 3 = 1 + (3 + 2) + (3 * 2 + 3)
M 4 = 1 + (4 + 2) + (4 * 2 + 3) + (4 * 3 + 4)
Notice? Now in a general view from n:
M n= 1 + (n + 2) + (n * 2 + 3) + (n * 3 + 4) + (n * 4 + 5) + ... + (n * (n-1) + n) We will
rearrange this (highlighted bold)
M n = 1 + (n + 2 ) + (n * 2 + 3 ) + (n * 3 + 4 ) + (n * 4 + 5 ) + ... + (n * (n-1) + n )
and this (in bold)
M n = 1 + ( n + 2) + ( n * 2 + 3) + ( n * 3 + 4) + ( n * 4 + 5) + ... + ( n * (n-1 ) + n)
and get:
M n = (1 + 2 + 3 + 4 + 5 + ... + n) + (n + n * 2 + n * 3 + n * 4 + ... + n * (n-1) )
put n out of the bracket:
M n = (1 + 2 + 3 + 4 + 5 + ... + n) + n * (1 + 2 + 3 + 4 + ... + (n-1)) [1]
Now we introduce a new designation ,
S n = 1 + 2 + 3 + ... + n [2]
, then
S n-1 = 1 + 2 + 3 + ... + (n-1) = S n - n [3]
Now we rewrite the formula [1] taking into account the notation [2] and [3], and get:
M n = S n + n * (S n - n) [4]
or so:
M n = Sn * (n + 1) - n 2
[5]
S n considering that - obviously calculated by the formula S n = n 2 /2 + n / 2 = n * (n + 1) / 2 is substituted in [5] : M n = S n * (n + 1) - n 2 = n * (n + 1) * (n + 1) / 2 - n 2 = n * (n 2 + 2 * n + 1 - 2 * n ) / 2 = n * (n 2 + 1) / 2 M n = n * (n 2 + 1) / 2 CTD