login
A004514
Generalized nim sum n + n in base 4.
5
0, 2, 0, 2, 8, 10, 8, 10, 0, 2, 0, 2, 8, 10, 8, 10, 32, 34, 32, 34, 40, 42, 40, 42, 32, 34, 32, 34, 40, 42, 40, 42, 0, 2, 0, 2, 8, 10, 8, 10, 0, 2, 0, 2, 8, 10, 8, 10, 32, 34, 32, 34, 40, 42, 40, 42, 32, 34, 32, 34, 40, 42, 40, 42, 128, 130, 128, 130, 136, 138, 136, 138, 128
OFFSET
0,2
FORMULA
Generalized nim sum m + n in base q: write m and n in base q and add mod q with no carries, e.g., 5 + 8 in base 3 = "21" + "22" = "10" = 1.
From Vladeta Jovovic, Feb 23 2003: (Start)
a(n) = 2*(n - a(floor(n/2))).
a(n) = 2*A063694(n). (End)
a(n) = A088442(n) - 1. - Chris Groer (cgroer(AT)math.uga.edu), Nov 10, 2003
a(n) = n + A053985(n). - Reinhard Zumkeller, Dec 27 2003
a(n) = A063695(2*n+1). - Reinhard Zumkeller, Sep 26 2015
a(n) = Sum_{k>=0} A030308(n,k)*A103424(k+1). - Philippe Deléham, Jan 12 2023
MATHEMATICA
A004514[n_]:= A004514[n]= If[n==0, 0, 2*n -2*A004514[Floor[n/2]]];
Table[A004514[n], {n, 0, 90}] (* G. C. Greubel, Dec 05 2022 *)
PROG
(Haskell)
a004514 = a063695 . (+ 1) . (* 2) -- Reinhard Zumkeller, Sep 26 2015
(Magma)
function A063694(n)
if n le 1 then return n;
else return 4*A063694(Floor(n/4)) + ((n mod 4) mod 2);
end if; return A063694;
end function;
A004514:= func< n | 2*A063694(n) >;
[A004514(n): n in [0..90]]; // G. C. Greubel, Dec 05 2022
(SageMath)
def A063694(n):
if (n<2): return n
else: return 4*A063694(floor(n/4)) + ((n%4)%2)
def A004514(n): return 2*A063694(n)
[A004514(n) for n in range(91)] # G. C. Greubel, Dec 05 2022
(PARI) a(n) = if(n, bitand(n, 2<<bitor(1, logint(n, 2)) \ 3)) << 1; \\ Kevin Ryde, Dec 10 2022
(Python)
def A004514(n): return (n&((1<<(m:=n.bit_length())+(m&1))-1)//3)<<1 # Chai Wah Wu, Jan 30 2023
CROSSREFS
KEYWORD
base,easy,nonn
EXTENSIONS
More terms from Reinhard Zumkeller, Dec 27 2003
STATUS
approved