OFFSET
0,3
LINKS
FORMULA
if n is a square then a(n) = a(sqrt(n))^2, otherwise if the difference between n and the highest square less than n is odd then a(n) = n+1, otherwise a(n) = (n-1)^2.
MATHEMATICA
a[n_] := a[n] = Which[r = Sqrt[n]; IntegerQ[r], a[r]^2, OddQ[n - Floor[r]^2], n+1, True, (n-1)^2]; a[0]=0; a[1]=1; Table[a[n], {n, 0, 58}] (* Jean-François Alcover, Aug 07 2012, after formula *)
PROG
(Haskell)
a054791 n = a054791_list `genericIndex` n
a054791_list = 0 : 1 : f 2 where
f x | r ^ 2 == x = a054791 r ^ 2 : f (x + 1)
| odd (x - r) = x + 1 : f (x + 1)
| otherwise = (x - 1) ^ 2 : f (x + 1)
where r = a000196 x
-- Reinhard Zumkeller, Oct 27 2013
CROSSREFS
KEYWORD
nice,nonn
AUTHOR
Henry Bottomley, Apr 27 2000
STATUS
approved