OFFSET
1,2
COMMENTS
Write out the natural numbers in a square counterclockwise spiral:
.
17--16--15--14--13
| |
18 5---4---3 12
| | | |
19 6 1---2 11
| | |
20 7---8---9--10
|
21--22--23--24--25
.
Now read off the numbers in a clockwise spiral: 1 -> 6 -> 5 -> 4 -> 3 -> 2 -> 9 -> etc.
LINKS
Eric M. Schmidt, Table of n, a(n) for n = 1..1000
MATHEMATICA
With[{x = Floor[(Floor[Sqrt[n-1]]+1)/2]}, Table[8*x^2-n+2 +x*If[n <= 4*x^2+2*x, -2, 6], {n, 1, 75}]] (* G. C. Greubel, Feb 05 2019 *)
PROG
(Sage)
def a(n):
x = (isqrt(n-1)+1)//2
return 8*x^2 + (-2 if n <= 4*x^2 + 2*x else 6)*x + 2 - n
[a(n) for n in (1..75)] # Eric M. Schmidt, May 18 2016
(PARI) {s(n)=floor((floor(sqrt(n-1)) +1)/2)};
for(n=1, 75, print1(8*s(n)^2 -n +2 +s(n)*if(n<= 2*s(n)*(2*s(n)+1), -2, 6), ", ")) \\ G. C. Greubel, Feb 05 2019
CROSSREFS
KEYWORD
easy,nonn
AUTHOR
Felix Tubiana, Feb 16 2004
EXTENSIONS
Offset corrected by Eric M. Schmidt, May 18 2016
STATUS
approved