cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-10 of 29 results. Next

A007953 Digital sum (i.e., sum of digits) of n; also called digsum(n).

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 8, 9, 10, 11, 12, 13, 14, 15
Offset: 0

Views

Author

R. Muller

Keywords

Comments

Do not confuse with the digital root of n, A010888 (first term that differs is a(19)).
Also the fixed point of the morphism 0 -> {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, 1 -> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 2 -> {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, etc. - Robert G. Wilson v, Jul 27 2006
For n < 100 equal to (floor(n/10) + n mod 10) = A076314(n). - Hieronymus Fischer, Jun 17 2007
It appears that a(n) is the position of 10*n in the ordered set of numbers obtained by inserting/placing one digit anywhere in the digits of n (except a zero before 1st digit). For instance, for n=2, the resulting set is (12, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 32, 42, 52, 62, 72, 82, 92) where 20 is at position 2, so a(2) = 2. - Michel Marcus, Aug 01 2022
Also the total number of beads required to represent n on a Russian abacus (schoty). - P. Christopher Staecker, Mar 31 2023
a(n) / a(2n) <= 5 with equality iff n is in A169964, while a(n) / a(3n) is unbounded, since if n = (10^k + 2)/3, then a(n) = 3*k+1, a(3n) = 3, so a(n) / a(3n) = k + 1/3 -> oo when k->oo (see Diophante link). - Bernard Schott, Apr 29 2023
Also the number of symbols needed to write number n in Egyptian numerals for n < 10^7. - Wojciech Graj, Jul 10 2025

Examples

			a(123) = 1 + 2 + 3 = 6, a(9875) = 9 + 8 + 7 + 5 = 29.
		

Crossrefs

Programs

  • Haskell
    a007953 n | n < 10 = n
              | otherwise = a007953 n' + r where (n',r) = divMod n 10
    -- Reinhard Zumkeller, Nov 04 2011, Mar 19 2011
    
  • Magma
    [ &+Intseq(n): n in [0..87] ];  // Bruno Berselli, May 26 2011
    
  • Maple
    A007953 := proc(n) add(d,d=convert(n,base,10)) ; end proc: # R. J. Mathar, Mar 17 2011
  • Mathematica
    Table[Sum[DigitCount[n][[i]] * i, {i, 9}], {n, 50}] (* Stefan Steinerberger, Mar 24 2006 *)
    Table[Plus @@ IntegerDigits @ n, {n, 0, 87}] (* or *)
    Nest[Flatten[# /. a_Integer -> Array[a + # &, 10, 0]] &, {0}, 2] (* Robert G. Wilson v, Jul 27 2006 *)
    Total/@IntegerDigits[Range[0,90]] (* Harvey P. Dale, May 10 2016 *)
    DigitSum[Range[0, 100]] (* Requires v. 14 *) (* Paolo Xausa, May 17 2024 *)
  • PARI
    a(n)=if(n<1, 0, if(n%10, a(n-1)+1, a(n/10))) \\ Recursive, very inefficient. A more efficient recursive variant: a(n)=if(n>9, n=divrem(n, 10); n[2]+a(n[1]), n)
    
  • PARI
    a(n, b=10)={my(s=(n=divrem(n, b))[2]); while(n[1]>=b, s+=(n=divrem(n[1], b))[2]); s+n[1]} \\ M. F. Hasler, Mar 22 2011
    
  • PARI
    a(n)=sum(i=1, #n=digits(n), n[i]) \\ Twice as fast. Not so nice but faster:
    
  • PARI
    a(n)=sum(i=1,#n=Vecsmall(Str(n)),n[i])-48*#n \\ M. F. Hasler, May 10 2015
    /* Since PARI 2.7, one can also use: a(n)=vecsum(digits(n)), or better: A007953=sumdigits. [Edited and commented by M. F. Hasler, Nov 09 2018] */
    
  • PARI
    a(n) = sumdigits(n); \\ Altug Alkan, Apr 19 2018
    
  • Python
    def A007953(n):
        return sum(int(d) for d in str(n)) # Chai Wah Wu, Sep 03 2014
    
  • Python
    def a(n): return sum(map(int, str(n))) # Michael S. Branicky, May 22 2021
    
  • Scala
    (0 to 99).map(.toString.map(.toInt - 48).sum) // Alonso del Arte, Sep 15 2019
    
  • Smalltalk
    "Recursive version for general bases. Set base = 10 for this sequence."
    digitalSum: base
    | s |
    base = 1 ifTrue: [^self].
    (s := self // base) > 0
      ifTrue: [^(s digitalSum: base) + self - (s * base)]
      ifFalse: [^self]
    "by Hieronymus Fischer, Mar 24 2014"
    
  • Swift
    A007953(n): String(n).compactMap{$0.wholeNumberValue}.reduce(0, +) // Egor Khmara, Jun 15 2021

Formula

a(A051885(n)) = n.
a(n) <= 9(log_10(n)+1). - Stefan Steinerberger, Mar 24 2006
From Benoit Cloitre, Dec 19 2002: (Start)
a(0) = 0, a(10n+i) = a(n) + i for 0 <= i <= 9.
a(n) = n - 9*(Sum_{k > 0} floor(n/10^k)) = n - 9*A054899(n). (End)
From Hieronymus Fischer, Jun 17 2007: (Start)
G.f. g(x) = Sum_{k > 0, (x^k - x^(k+10^k) - 9x^(10^k))/(1-x^(10^k))}/(1-x).
a(n) = n - 9*Sum_{10 <= k <= n} Sum_{j|k, j >= 10} floor(log_10(j)) - floor(log_10(j-1)). (End)
From Hieronymus Fischer, Jun 25 2007: (Start)
The g.f. can be expressed in terms of a Lambert series, in that g(x) = (x/(1-x) - 9*L[b(k)](x))/(1-x) where L[b(k)](x) = sum{k >= 0, b(k)*x^k/(1-x^k)} is a Lambert series with b(k) = 1, if k > 1 is a power of 10, else b(k) = 0.
G.f.: g(x) = (Sum_{k > 0} (1 - 9*c(k))*x^k)/(1-x), where c(k) = Sum_{j > 1, j|k} floor(log_10(j)) - floor(log_10(j-1)).
a(n) = n - 9*Sum_{0 < k <= floor(log_10(n))} a(floor(n/10^k))*10^(k-1). (End)
From Hieronymus Fischer, Oct 06 2007: (Start)
a(n) <= 9*(1 + floor(log_10(n))), equality holds for n = 10^m - 1, m > 0.
lim sup (a(n) - 9*log_10(n)) = 0 for n -> oo.
lim inf (a(n+1) - a(n) + 9*log_10(n)) = 1 for n -> oo. (End)
a(n) = A138530(n, 10) for n > 9. - Reinhard Zumkeller, Mar 26 2008
a(A058369(n)) = A004159(A058369(n)); a(A000290(n)) = A004159(n). - Reinhard Zumkeller, Apr 25 2009
a(n) mod 2 = A179081(n). - Reinhard Zumkeller, Jun 28 2010
a(n) <= 9*log_10(n+1). - Vladimir Shevelev, Jun 01 2011
a(n) = a(n-1) + a(n-10) - a(n-11), for n < 100. - Alexander R. Povolotsky, Oct 09 2011
a(n) = Sum_{k >= 0} A031298(n, k). - Philippe Deléham, Oct 21 2011
a(n) = a(n mod b^k) + a(floor(n/b^k)), for all k >= 0. - Hieronymus Fischer, Mar 24 2014
Sum_{n>=1} a(n)/(n*(n+1)) = 10*log(10)/9 (Shallit, 1984). - Amiram Eldar, Jun 03 2021

Extensions

More terms from Hieronymus Fischer, Jun 17 2007
Edited by Michel Marcus, Nov 11 2013

A003132 Sum of squares of digits of n.

Original entry on oeis.org

0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 1, 2, 5, 10, 17, 26, 37, 50, 65, 82, 4, 5, 8, 13, 20, 29, 40, 53, 68, 85, 9, 10, 13, 18, 25, 34, 45, 58, 73, 90, 16, 17, 20, 25, 32, 41, 52, 65, 80, 97, 25, 26, 29, 34, 41, 50, 61, 74, 89, 106, 36, 37, 40, 45, 52, 61, 72, 85, 100, 117, 49
Offset: 0

Views

Author

Keywords

Comments

It is easy to show that a(n) < 81*(log_10(n)+1). - Stefan Steinerberger, Mar 25 2006
It is known that a(0)=0 and a(1)=1 are the only fixed points of this map. For more information about iterations of this map, see A007770, A099645 and A000216 ff. - M. F. Hasler, May 24 2009
Also known as the "Happy number map", since happy numbers A007770 are those whose trajectory under iterations of this map ends at 1. - M. F. Hasler, Jun 03 2025

References

  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
  • Hugo Steinhaus, One Hundred Problems in Elementary Mathematics, Dover New York, 1979, republication of English translation of Sto Zadań, Basic Books, New York, 1964. Chapter I.2, An interesting property of numbers, pp. 11-12 (available on Google Books).

Crossrefs

Concerning iterations of this map, see A003621, A039943, A099645, A031176, A007770, A000216 (starting with 2), A000218 (starting with 3), A080709 (starting with 4, this is the only nontrivial limit cycle), A000221 (starting with 5), A008460 (starting with 6), A008462 (starting with 8), A008463 (starting with 9), A139566 (starting with 15), A122065 (starting with 74169). - M. F. Hasler, May 24 2009
Cf. A080151, A051885 (record values and where they occur).

Programs

  • Haskell
    a003132 0 = 0
    a003132 x = d ^ 2 + a003132 x' where (x', d) = divMod x 10
    -- Reinhard Zumkeller, May 10 2015, Aug 07 2012, Jul 10 2011
    
  • Magma
    [0] cat [&+[d^2: d in Intseq(n)]: n in [1..80]]; // Bruno Berselli, Feb 01 2013
    
  • Maple
    A003132 := proc(n) local d; add(d^2,d=convert(n,base,10)) ; end proc: # R. J. Mathar, Oct 16 2010
  • Mathematica
    Table[Sum[DigitCount[n][[i]]*i^2, {i, 1, 9}], {n, 0, 40}] (* Stefan Steinerberger, Mar 25 2006 *)
    Total/@(IntegerDigits[Range[0,80]]^2) (* Harvey P. Dale, Jun 20 2011 *)
  • PARI
    A003132(n)=norml2(digits(n)) \\ M. F. Hasler, May 24 2009, updated Apr 12 2015
    
  • Python
    def A003132(n): return sum(int(d)**2 for d in str(n)) # Chai Wah Wu, Apr 02 2021

Formula

a(n) = n^2 - 20*n*floor(n/10) + 81*(Sum_{k>0} floor(n/10^k)^2) + 20*Sum_{k>0} floor(n/10^k)*(floor(n/10^k) - floor(n/10^(k+1))). - Hieronymus Fischer, Jun 17 2007
a(10n+k) = a(n)+k^2, 0 <= k < 10. - Hieronymus Fischer, Jun 17 2007
a(n) = A007953(A048377(n)) - A007953(n). - Reinhard Zumkeller, Jul 10 2011

Extensions

More terms from Stefan Steinerberger, Mar 25 2006
Terms checked using the given PARI code, M. F. Hasler, May 24 2009
Replaced the Maple program with a version which works also for arguments with >2 digits, R. J. Mathar, Oct 16 2010
Added ref to Porges. Steinhaus also treated iterations of this function in his Polish book Sto zadań, but I don't have access to it. - Don Knuth, Sep 07 2015

A055012 Sum of cubes of the digits of n written in base 10.

Original entry on oeis.org

0, 1, 8, 27, 64, 125, 216, 343, 512, 729, 1, 2, 9, 28, 65, 126, 217, 344, 513, 730, 8, 9, 16, 35, 72, 133, 224, 351, 520, 737, 27, 28, 35, 54, 91, 152, 243, 370, 539, 756, 64, 65, 72, 91, 128, 189, 280, 407, 576, 793, 125, 126, 133, 152, 189, 250, 341, 468, 637, 854
Offset: 0

Views

Author

Henry Bottomley, May 31 2000

Keywords

Comments

For n > 1999, a(n) < n. The iteration of this map on n either stops at a fixed point (A046197) or has a period of 2 or 3: {55,250,133}, {136,244}, {160,217,352}, or {919,1459}. - T. D. Noe, Jul 17 2007
A165330 and A165331 give the final value and the number of steps when iterating until a fixed point or cycle is reached. - Reinhard Zumkeller, Sep 17 2009

Crossrefs

Cf. A046197 Fixed points; A046459: integers equal to the sum of the digits of their cubes; A072884: 3rd-order digital invariants: the sum of the cubes of the digits of n equals some number k and the sum of the cubes of the digits of k equals n; A164883: cubes with the property that the sum of the cubes of the digits is also a cube.

Programs

  • Magma
    [0] cat [&+[d^3: d in Intseq(n)]: n in [1..60]]; // Bruno Berselli, Feb 01 2013
    
  • Maple
    A055012 := proc(n)
            add(d^3,d=convert(n,base,10)) ;
    end proc: # R. J. Mathar, Dec 15 2011
  • Mathematica
    Total/@((IntegerDigits/@Range[0,60])^3) (* Harvey P. Dale, Jan 27 2012 *)
    Table[Sum[DigitCount[n][[i]] i^3, {i, 9}], {n, 0, 60}] (* Bruno Berselli, Feb 01 2013 *)
  • PARI
    A055012(n)=sum(i=1,#n=digits(n),n[i]^3) \\ Charles R Greathouse IV, Jul 01 2013
    
  • Python
    def a(n): return sum(map(lambda x: x*x*x, map(int, str(n))))
    print([a(n) for n in range(60)]) # Michael S. Branicky, Jul 13 2022

Formula

a(n) = Sum_{k>=1} (floor(n/10^k) - 10*floor(n/10^(k+1)))^3. - Hieronymus Fischer, Jun 25 2007
a(10n+k) = a(n) + k^3, 0 <= k < 10. - Hieronymus Fischer, Jun 25 2007
From Reinhard Zumkeller, Sep 17 2009: (Start)
a(n) <= 729*A055642(n);
a(A165370(n)) = n and a(m) <> n for m < A165370(n);
a(A031179(n)) = A031179(n);
a(a(A165336(n))) = A165336(n) or a(a(a(A165336(n)))) = A165336(n). (End)
G.f. g(x) = Sum_{k>=0} (1-x^(10^k))*(x^(10^k)+8*x^(2*10^k)+27*x^(3*10^k)+64*x^(4*10^k)+125*x^(5*10^k)+216*x^(6*10^k)+343*x^(7*10^k)+512*x^(8*10^k)+729*x^(9*10^k))/((1-x)*(1-x^(10^(k+1))))
satisfies
g(x) = (x+8*x^2+27*x^3+64*x^4+125*x^5+216*x^6+343*x^7+512*x^8+729*x^9)/(1-x^10) + (1-x^10)*g(x^10)/(1-x). - Robert Israel, Jan 26 2017

Extensions

Edited by M. F. Hasler, Apr 12 2015
Iséki and Stewart links added by Don Knuth, Sep 07 2015

A065359 Alternating bit sum for n: replace 2^k with (-1)^k in binary expansion of n.

Original entry on oeis.org

0, 1, -1, 0, 1, 2, 0, 1, -1, 0, -2, -1, 0, 1, -1, 0, 1, 2, 0, 1, 2, 3, 1, 2, 0, 1, -1, 0, 1, 2, 0, 1, -1, 0, -2, -1, 0, 1, -1, 0, -2, -1, -3, -2, -1, 0, -2, -1, 0, 1, -1, 0, 1, 2, 0, 1, -1, 0, -2, -1, 0, 1, -1, 0, 1, 2, 0, 1, 2, 3, 1, 2, 0, 1, -1, 0, 1, 2, 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 1, 2, 0, 1, 2, 3, 1, 2, 0, 1, -1, 0, 1, 2, 0, 1, -1, 0, -2
Offset: 0

Views

Author

Marc LeBrun, Oct 31 2001

Keywords

Comments

Notation: (2)[n](-1)
From David W. Wilson and Ralf Stephan, Jan 09 2007: (Start)
a(n) is even iff n in A001969; a(n) is odd iff n in A000069.
a(n) == 0 (mod 3) iff n == 0 (mod 3).
a(n) == 0 (mod 6) iff (n == 0 (mod 3) and n/3 not in A036556).
a(n) == 3 (mod 6) iff (n == 0 (mod 3) and n/3 in A036556). (End)
a(n) = A030300(n) - A083905(n). - Ralf Stephan, Jul 12 2003
From Robert G. Wilson v, Feb 15 2011: (Start)
First occurrence of k and -k: 0, 1, 2, 5, 10, 21, 42, 85, ..., (A000975); i.e., first 0 occurs for 0, first 1 occurs for 1, first -1 occurs at 2, first 2 occurs for 5, etc.;
a(n)=-3 only if n mod 3 = 0,
a(n)=-2 only if n mod 3 = 1,
a(n)=-1 only if n mod 3 = 2,
a(n)= 0 only if n mod 3 = 0,
a(n)= 1 only if n mod 3 = 1,
a(n)= 2 only if n mod 3 = 2,
a(n)= 3 only if n mod 3 = 0, ..., . (End)
a(n) modulo 2 is the Prouhet-Thue-Morse sequence A010060. - Philippe Deléham, Oct 20 2011
In the Koch curve, number the segments starting with n=0 for the first segment. The net direction (i.e., the sum of the preceding turns) of segment n is a(n)*60 degrees. This is since in the curve each base-4 digit 0,1,2,3 of n is a sub-curve directed respectively 0, +60, -60, 0 degrees, which is the net 0,+1,-1,0 of two bits in the sum here. - Kevin Ryde, Jan 24 2020

Examples

			Alternating bit sum for 11 = 1011 in binary is 1 - 1 + 0 - 1 = -1, so a(11) = -1.
		

Crossrefs

Cf. A005536 (partial sums), A056832 (abs first differences), A010060 (mod 2), A039004 (indices of 0's).
Cf. also A004718.
Cf. analogous sequences for bases 3-10: A065368, A346688, A346689, A346690, A346691, A346731, A346732, A055017 and also A373605 (for primorial base).

Programs

  • Haskell
    a065359 0 = 0
    a065359 n = - a065359 n' + m where (n', m) = divMod n 2
    -- Reinhard Zumkeller, Mar 20 2015
    
  • Maple
    A065359 := proc(n) local dgs ; dgs := convert(n,base,2) ; add( -op(i,dgs)*(-1)^i,i=1..nops(dgs)) ; end proc: # R. J. Mathar, Feb 04 2011
  • Mathematica
    f[0]=0; f[n_] := Plus @@ (-(-1)^Range[ Floor[ Log2@ n + 1]] Reverse@ IntegerDigits[n, 2]); Array[ f, 107, 0]
  • PARI
    a(n) = my(s=0, u=1); for(k=0,#binary(n)-1,s+=bittest(n,k)*u;u=-u);s /* Washington Bomfim, Jan 18 2011 */
    
  • PARI
    a(n) = my(b=binary(n)); b*[(-1)^k|k<-[-#b+1..0]]~; \\ Ruud H.G. van Tol, Oct 16 2023
    
  • PARI
    a(n) = if(n==0, 0, 2*hammingweight(bitand(n, ((4<<(2*logint(n,4)))-1)/3)) - hammingweight(n)) \\ Andrew Howroyd, Dec 14 2024
    
  • Python
    def a(n):
        return sum((-1)**k for k, bi in enumerate(bin(n)[2:][::-1]) if bi=='1')
    print([a(n) for n in range(107)]) # Michael S. Branicky, Jul 13 2021
    
  • Python
    from sympy.ntheory import digits
    def A065359(n): return sum((0,1,-1,0)[i] for i in digits(n,4)[1:]) # Chai Wah Wu, Jul 19 2024

Formula

G.f.: (1/(1-x)) * Sum_{k>=0} (-1)^k*x^2^k/(1+x^2^k). - Ralf Stephan, Mar 07 2003
a(0) = 0, a(2n) = -a(n), a(2n+1) = 1-a(n). - Ralf Stephan, Mar 07 2003
a(n) = Sum_{k>=0} A030308(n,k)*(-1)^k. - Philippe Deléham, Oct 20 2011
a(n) = -a(floor(n/2)) + n mod 2. - Reinhard Zumkeller, Mar 20 2015
a(n) = A139351(n) - A139352(n). - Kevin Ryde, Jan 24 2020
G.f. A(x) satisfies: A(x) = x / (1 - x^2) - (1 + x) * A(x^2). - Ilya Gutkovskiy, Jul 28 2021
a(n) = A195017(A019565(n)). - Antti Karttunen, Jun 19 2024

Extensions

More terms from Ralf Stephan, Jul 12 2003

A055013 Sum of 4th powers of digits of n.

Original entry on oeis.org

0, 1, 16, 81, 256, 625, 1296, 2401, 4096, 6561, 1, 2, 17, 82, 257, 626, 1297, 2402, 4097, 6562, 16, 17, 32, 97, 272, 641, 1312, 2417, 4112, 6577, 81, 82, 97, 162, 337, 706, 1377, 2482, 4177, 6642, 256, 257, 272, 337, 512, 881, 1552, 2657, 4352, 6817
Offset: 0

Views

Author

Henry Bottomley, May 31 2000

Keywords

Comments

Fixed points are listed in A052455, row 4 of A252648. See also A061210. - M. F. Hasler, Apr 12 2015

Crossrefs

Programs

  • Magma
    [0] cat [&+[d^4: d in Intseq(n)]: n in [1..50]]; // Bruno Berselli, Feb 01 2013
    
  • Maple
    A055013 := proc(n)
            add(d^4,d=convert(n,base,10)) ;
    end proc:
    seq(A055013(n),n=0..20) ; # R. J. Mathar, Nov 07 2011
  • Mathematica
    Table[Sum[DigitCount[n][[i]] i^4, {i, 9}], {n, 0, 50}] (* Bruno Berselli, Feb 01 2013 *)
    Table[Total[IntegerDigits[n]^4],{n,0,50}] (* Harvey P. Dale, Jul 28 2019 *)
  • PARI
    a(n)=round(normlp(n,4)^4) \\ Quite slow. - M. F. Hasler, Apr 12 2015
    
  • PARI
    A055013(n)=sum(i=1,#n=digits(n),n[i]^4) \\ M. F. Hasler, Apr 12 2015

Formula

a(n) = sum{k>0, (floor(n/10^k)-10*floor(n/10^(k+1)))^4}. - Hieronymus Fischer, Jun 25 2007
a(10n+k) = a(n)+k^4, 0<=k<10. - Hieronymus Fischer, Jun 25 2007

A055014 Sum of 5th powers of digits of n.

Original entry on oeis.org

0, 1, 32, 243, 1024, 3125, 7776, 16807, 32768, 59049, 1, 2, 33, 244, 1025, 3126, 7777, 16808, 32769, 59050, 32, 33, 64, 275, 1056, 3157, 7808, 16839, 32800, 59081, 243, 244, 275, 486, 1267, 3368, 8019, 17050, 33011, 59292, 1024, 1025, 1056, 1267, 2048
Offset: 0

Views

Author

Henry Bottomley, May 31 2000

Keywords

Comments

Fixed points are listed in A052464. - M. F. Hasler, Apr 12 2015

Crossrefs

Programs

  • Magma
    [0] cat [&+[d^5: d in Intseq(n)]: n in [1..45]]; // Bruno Berselli, Feb 01 2013
    
  • Maple
    A055014 := proc(n)
       add(d^5,d=convert(n,base,10)) ;
    end proc: # R. J. Mathar, Jul 08 2012
  • Mathematica
    Total/@(IntegerDigits[Range[50]]^5)  (* Harvey P. Dale, Jan 22 2011 *)
    Table[Sum[DigitCount[n][[i]] i^5, {i, 9}], {n, 0, 45}] (* Bruno Berselli, Feb 01 2013 *)
  • PARI
    A055014(n)=sum(i=1, #n=digits(n), n[i]^5) \\ M. F. Hasler, Apr 12 2015

Formula

a(n) = Sum_{k>=1} (floor(n/10^k) - 10*floor(n/10^(k+1)))^5. - Hieronymus Fischer, Jun 25 2007
a(10n+k) = a(n) + k^5, 0 <= k < 10. - Hieronymus Fischer, Jun 25 2007

A225693 Alternating sum of digits of n.

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, 8, 7, 6, 5, 4, 3, 2
Offset: 0

Views

Author

N. J. A. Sloane, May 27 2013

Keywords

Comments

A number n is divisible by 11 if and only if a(n) is divisible by 11. For generalizations see Sharpe and Webster, or the links below.
The primes p for which the absolute value of the alternating sum of digits of p is also a prime begin: 2, 3, 5, 7, 13, 29, 31, 41, 47, 53, 61, 79, 83, 97, 101, 113, 137, 139, 151. - Jonathan Vos Post, May 27 2013
The above prime sequence is A115261. - Jens Kruse Andersen, Jul 13 2014
Digital sum with alternating signs starting with a positive sign for the most significant digit. - Hieronymus Fischer, Mar 23 2014

Crossrefs

A055017 is closely related (but less natural).
Cf. A061479.
Cf. A004086.
Indices of 0..3: A135499, A061470, A061471, A061472.

Programs

  • Haskell
    a225693 = f 1 0 where
       f _ a 0 = a
       f s a x = f (negate s) (s * a + d) x' where (x', d) = divMod x 10
    -- Reinhard Zumkeller, May 11 2015, Aug 08 2014
    
  • Maple
    A225693 :=proc(n) local t1,i;
    t1:=convert(n,base,10);
    add((-1)^(i+nops(t1))*t1[i],i=1..nops(t1));
    end;
    [seq(A225693(n),n=0..120)];
  • Mathematica
    Table[Total[Times@@@Partition[Riffle[IntegerDigits[n],{1,-1},{2,-1,2}],2]],{n,0,90}] (* Harvey P. Dale, Nov 27 2015 *)
  • PARI
    a(n) = my(d=digits(n)); sum(k=1, #d, (-1)^(k+1)*d[k]); \\ Michel Marcus, Jul 15 2022
  • Python
    def a(n): return sum(int(d)*(-1)**i for i, d in enumerate(str(n)))
    print([a(n) for n in range(87)]) # Michael S. Branicky, Jul 14 2022
    
  • Smalltalk
    "Version for general bases"
    "Set base = 10 for this sequence"
    altDigitalSumLeft: base
    base > 1 ifTrue:  [m:= self integerFloorLog: base]
             ifFalse: [^self \\ 2].
    p:=1.
    s:=0.
    1 to: m by: 2 do: [ :k |
        p := p*base.
        s := s - (self // p) .
        p := p*base.
        s := s + (self // p) ].
    ^(self + ((base + 1)*s)) * (m alternate)
    "Version for base 10 using altDigitalSumRight from A055017"
    A225693
    ^(self A004086) altDigitalSumLeft: 10
    [by Hieronymus Fischer, Mar 23 2014]
    

Formula

If n has decimal expansion abc..xyz with least significant digit z, a(n) = a - b + c - d + ...
From Hieronymus Fischer, Mar 23 2014: (Start)
Formulas for general bases b > 1 (b = 10 for this sequence). Always m := floor(log_b(n)).
a(n) = Sum_{k>=0} (-1)^k*(floor(n*b^(k-m)) mod b). The sum is finite with floor(log_b(n)) as the highest index.
a(n) = (-1)^m*n - (b+1)*Sum_{k=1..m} (-1)^k*floor(n*b^(k-m-1)).
a(n) = (-1)^m*(n + (b+1)*Sum_{k>=1} (-1)^k*floor(n/b^k)).
a(n) = -(-1)^(m-k)*a(n mod b^k) + a(floor(n/b^k)), for 0 <= k <= m+1.
a(n) = (-1)^m*a(n mod b) + a(floor(n/b)).
a(n) = -(-1)^m*a(n mod b^2) + a(floor(n/b^2)).
a(n) = (-1)^m*A055017(n).
a(n) = A055017(A004086(n)).
a(A004086(A004086(n))) = a(n).
(End)
a(A135499(n)) = 0; a(A061470(n)) = 1. - Reinhard Zumkeller, Aug 08 2014
a(A061471(n)) = 2; a(A061472(n)) = 3. - Bernard Schott, Jul 14 2022

Extensions

Comment corrected by Jens Kruse Andersen, Jul 13 2014

A040997 Absolute value of first digit of n minus sum of other digits of n.

Original entry on oeis.org

1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Offset: 1

Views

Author

Keywords

Comments

This is different from |A055017(n)| = |(x1 + x3 + ...) - (x2 + x4 + ...)|, where x1,...,xk are the digits of n. - M. F. Hasler, Nov 09 2019

Examples

			a(371) = |3-7-1| = 5.
		

Crossrefs

Programs

  • Haskell
    a040997 n = abs $ a000030 n - a007953 (a217657 n) -- Reinhard Zumkeller, Oct 10 2012
    
  • PARI
    apply( A040997(n)={abs(vecsum(n=digits(n))-n[1]*2)}, [1..199]) \\ M. F. Hasler, Nov 09 2019

Formula

If decimal expansion of n is x1 x2 ... xk then a(n) = |x1-x2-x3- ... -xk|.
a(n) = abs(A000030(n) - A007953(A217657(n))). - Reinhard Zumkeller, Oct 10 2012

Extensions

Name edited and incorrect formula deleted by M. F. Hasler, Nov 09 2019

A076314 a(n) = floor(n/10) + (n mod 10).

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 8, 9, 10, 11, 12, 13, 14
Offset: 0

Views

Author

Reinhard Zumkeller, Oct 06 2002

Keywords

Comments

For n<100 this is equal to the digital sum of n (see A007953). - Hieronymus Fischer, Jun 17 2007

Examples

			a(15) = floor(15 / 10) + (15 mod 10) = 1 + 5 = 6. - _Indranil Ghosh_, Feb 13 2017
		

Crossrefs

Programs

Formula

From Hieronymus Fischer, Jun 17 2007: (Start)
a(n) = n - 9*floor(n/10).
a(n) = (n + 9*(n mod 10))/10.
a(n) = n - 9*A002266(A004526(n)) = n - 9*A004526(A002266(n)).
a(n) = (n + 9*A010879(n))/10.
a(n) = (n + 9*A000035(n) + 18*A010874(A004526(n)))/10.
a(n) = (n + 9*A010874(n) + 45*A000035(A002266(n)))/10.
G.f.: x*(8*x^10 - 9*x^9 + 1)/((1 - x^10)*(1 - x)^2). (End)
a(n) = A033930(n) for 1 <= n < 100. - R. J. Mathar, Sep 21 2008
a(n) = +a(n-1) + a(n-10) - a(n-11). - R. J. Mathar, Feb 20 2011

A076313 a(n) = floor(n/10) - (n mod 10).

Original entry on oeis.org

0, -1, -2, -3, -4, -5, -6, -7, -8, -9, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, 8, 7, 6, 5, 4
Offset: 0

Views

Author

Reinhard Zumkeller, Oct 06 2002

Keywords

Comments

For n<100 equal to the negated alternating digital sum of n (see A055017). - Hieronymus Fischer, Jun 17 2007

Crossrefs

Programs

  • Haskell
    a076313 = uncurry (-) . flip divMod 10 -- Reinhard Zumkeller, Jun 01 2013
  • Mathematica
    Table[Floor[n/10]-Mod[n,10],{n,0,100}] (* or *) LinearRecurrence[{1,0,0,0,0,0,0,0,0,1,-1},{0,-1,-2,-3,-4,-5,-6,-7,-8,-9,1},100] (* Harvey P. Dale, Nov 02 2022 *)
  • PARI
    a(n)=n\10-n%10 \\ Charles R Greathouse IV, Jan 30 2012
    

Formula

From Hieronymus Fischer, Jun 17 2007: (Start)
a(n) = 11*floor(n/10)-n.
a(n) = (n-11*(n mod 10))/10.
a(n) = 11*A002266(A004526(n))-n=11*A004526(A002266(n))-n.
a(n) = (n-11*A010879(n))/10.
a(n) = (n-11*A000035(n)-22*A010874(A004526(n)))/10.
a(n) = (n-11*A010874(n)-55*A000035(A002266(n)))/10.
G.f.: x*(-8*x^10+11*x^9-1)/((1-x^10)*(1-x)^2). (End)
Showing 1-10 of 29 results. Next