|
|
A236345
|
|
a(n) is the Manhattan distance between n and n^2 in a left-aligned triangle with next M natural numbers in row M: 1, 2 3, 4 5 6, 7 8 9 10, etc.
|
|
4
|
|
|
0, 1, 3, 3, 6, 10, 9, 14, 9, 15, 11, 18, 26, 17, 26, 19, 29, 40, 27, 39, 24, 42, 27, 39, 54, 35, 51, 36, 53, 71, 48, 67, 42, 62, 83, 56, 85, 56, 79, 48, 72, 97, 64, 90, 55, 90, 118, 81, 110, 71, 101, 68, 91, 123, 80, 122, 77, 111, 146, 99, 135, 86, 123, 88, 110
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,3
|
|
LINKS
|
|
|
FORMULA
|
|
|
EXAMPLE
|
The triangle where we measure distances begins as (cf. A000027 drawn as a lower or upper right triangle):
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
Manhattan distance between 5 and 25 in this triangle is 4+2=6, thus a(5)=6.
|
|
PROG
|
(Python)
import math
def getXY(n):
y = int(math.sqrt(n*2))
if n<=y*(y+1)//2: y-=1
x = n - y*(y+1)//2
return x, y
for n in range(1, 77):
ox, oy = getXY(n)
nx, ny = getXY(n*n)
print(str(abs(nx-ox)+abs(ny-oy)), end=', ')
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn,easy
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|