Numbers on Spiral Diagonals

C++, Matlab. This is the problem 28 from Project Euler website.

Question: Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:

21 22 23 24 25
20  7  8  9 10
19  6  1  2 11
18  5  4  3 12
17 16 15 14 13

It can be verified that the sum of the numbers on the diagonals is 101.

What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way? Link to question page.

Solution: My approach is to detect the related sequences depending on the dimension. For example;
1 for n=1

3,5,7,9 for n=3

3,5,7,9,13,17,21,25  for n=5

3,5,7,9,13,17,21,25,31,37,43,49  for n=7  and so on…

That shows, for every n, 4 elements are added to the sequence as well. The increment value among elements depends on n level. For example, increment value is 2 for n=3 whereas it is 4 for n=5. The result for 1001 x 1001 matrix is 669171001.

MATLAB version;