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.
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
Offset: 1
Examples
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.
Links
- Antti Karttunen, Table of n, a(n) for n = 1..1001
Programs
-
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=',')
-
Python
from math import isqrt, comb def A236345(n): return (isqrt(n**2<<3)+1>>1)-(isqrt(n<<3)+1>>1)+abs(n*(n-1)-comb((m2:=isqrt(k2:=n**2<<1))+(k2>m2*(m2+1)),2)+comb((m:=isqrt(k:=n<<1))+(k>m*(m+1)),2)) # Chai Wah Wu, Jun 07 2025
-
Scheme
(define (A236345 n) (+ (- (A002024 (A000290 n)) (A002024 n)) (abs (- (A002260 (A000290 n)) (A002260 n))))) ;; Antti Karttunen, Jan 25 2014
Formula
a(n) = (A002024(n^2)-A002024(n)) + |A002260(n^2)-A002260(n)|. [Where |x| stands for the absolute value. This formula can be probably reduced further.] - Antti Karttunen, Jan 25 2014