A384212 a(n) is the number of bases >= 2 in which the alternating sum of digits of n is equal to 0.
0, 0, 1, 1, 1, 2, 1, 2, 2, 2, 1, 4, 1, 2, 3, 3, 1, 4, 1, 3, 2, 2, 1, 6, 2, 2, 3, 4, 1, 6, 1, 4, 3, 2, 2, 7, 1, 2, 3, 6, 1, 5, 1, 4, 5, 2, 1, 8, 2, 3, 3, 4, 1, 5, 2, 6, 3, 2, 1, 9, 1, 2, 5, 5, 3, 6, 1, 4, 2, 6, 1, 10, 1, 2, 5, 4, 2, 5, 1, 8, 3, 2, 1, 8, 3, 2, 2
Offset: 1
Examples
a(72) = 10 because the alternating sum of digits of n is equal to 0 in the 10 bases 2 [1, 0, 0, 1, 0, 0, 0], 3 [2, 2, 0, 0], 5 [2, 4, 2], 7 [1, 3, 2], 8 [1, 1, 0], 11 [6, 6], 17 [4, 4], 23 [3, 3], 35 [2, 2] and 71 [1, 1].
Links
- Felix Huber, Table of n, a(n) for n = 1..10000
Programs
-
Maple
A384212:=proc(n) local a,b,c,i; a:=0; for b from 2 to n-1 do c:=convert(n,'base',b); if add(c[i]*(-1)^i,i=1..nops(c))=0 then a:=a+1 fi od; return a end proc; seq(A384212(n),n=1..87); A384212bases:=proc(n) local L,b,c,i; L:=[]; for b from 2 to n-1 do c:=convert(n,'base',b); if add(c[i]*(-1)^i,i=1..nops(c))=0 then L:=[op(L),b,ListTools:-Reverse(c)] fi od; return op(L) end proc; A384212bases(72);
-
Mathematica
q[n_, b_] := Module[{d = IntegerDigits[n, b]}, Sum[(-1)^k*d[[k]], {k, 1, Length[d]}] == 0 ]; a[n_] := Count[Range[2, n-1], ?(q[n, #] &)]; Array[a, 100] (* _Amiram Eldar, May 24 2025 *)
-
PARI
a(n) = sum(b=2, n-1, my(d=digits(n, b)); sum(k=1, #d, (-1)^k*d[k]) == 0); \\ Michel Marcus, May 24 2025
-
Python
from sympy.ntheory import digits def s(v): return sum(v[::2]) - sum(v[1::2]) def a(n): return sum(1 for b in range(2, n) if s(digits(n, b)[1:]) == 0) print([a(n) for n in range(1, 87)]) # Michael S. Branicky, May 24 2025
Formula
Trivial bounds: 1 <= a(n) <= n - 2 for n >= 3 because the representation of n in base n-1 is [1,1] and the alternating sum of digits of n is > 0 for bases >= n.
Comments