# Magic constant

There are some squares that are called magical. Well, probably everyone knows that the sum of numbers in such squares along horizontals, verticals and main diagonals is the same, that is, equal to the same number, this number-sum is called the

Writing again the numbers in squares, once noticed such a thing. If you enter numbers from 1 to n

M

2

M

2

3

According to the formula:

M

M

On the diagonals (bold above):

M

M

Unlike the formula, the diagonals are able to give an answer what happens. Consider the numbers on the diagonals:

M

M

Rewrite it differently:

M

M

Notice? Now in a general view from n:

M

rearrange this (highlighted bold)

M

and this (in bold)

M

and get:

M

put n out of the bracket:

M

Now we introduce a new designation ,

S

, then

S

Now we rewrite the formula [1] taking into account the notation [2] and [3], and get:

or so:

S

**(M***magic constant*_{n}, where n is the size of the square; n> 2). Back in school, I remember the formula for calculating this constant: M_{n}= n * (n^{2}+ 1) / 2, it was not clear for me where it came from ... here we will try to derive it, maybe someone has already deduced it, maybe also Perhaps in a different way, it doesnâ€™t matter just to write.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**143

**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 = 15M

_{4}= n * (n^{2}+ 1) / 2 = 4 * (4 * 4 + 1) / 2 = 68/2 = 34On the diagonals (bold above):

M

_{3}= 1 + 5 + 9 = 15M

_{4}= 1 + 6 + 11 + 16 = 34Unlike the formula, the diagonals are able to give an answer what happens. Consider the numbers on the diagonals:

M

_{3}= 1 + 5 + 9M

_{4}= 1 + 6 + 11 + 16Rewrite 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 willrearrange 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}= S_{n}* (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_{}^{}_{}_{}^{}^{}^{}^{}_{}^{}