The best way to solve this question is math
57 58 59 60 61 62 63 64 65
56 31 32 33 34 35 36 37 66
55 30 13 14 15 16 17 38 67
54 29 12 3 4 5 18 39 68
53 28 11 2 1 6 19 40 69
52 27 10 9 8 7 20 41 70
51 26 25 24 23 22 21 42 71
50 49 48 47 46 45 44 43 72
81 80 79 78 77 76 75 74 73 |
You will notice that numbers from the center to the lower-left corner are odd perfect squares
They have the general formula (2n-1)
2 (taking the center to be at index 1)
Write numbers from the center to any corner in a line:
Example, upper left corner
1 3 13 31 57
Take their differences
2 10 18 26
Again take differences
8 8 8
The differences come out to be constant.
Hence it is a series where differences of successive terms are in Arithmetic Progression
Let the general term be f(n)=an
2+bn+c
f(1)=a+b+c
f(2)=4a+2b+c
f(3)=9a+3b+c
Solve the 3 equations to get
a=4, b=-10, c=7
Hence, general term is 4n
2-10n+7
To obtain the sum of the numbers, summate the series
(ie. replace n
2 by n(n+1)(2n+1)/6, n by n(n+1)/2, and multiply constant term by n)
(ans: n(4n
2-9n+8)/3)
Similarly find other sums
upper-right: n(4n
2-6n+5)/3
lower-right: n(4n
2-3n+2)/3
lower-left: n(2n-1)(2n+1)/3
Add them and subtract 3 to get
(16n3-18n2+14n-9)/3
For the pattern given above, substitute n=5 to get the sum as 537
If n=3, sum=101
So you have a simple formula in which you can put values. No need for a lengthy program!