login
The OEIS Foundation is supported by donations from users of the OEIS and by a grant from the Simons Foundation.

 

Logo


Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A225693 Alternating sum of digits of n. 15
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 (list; graph; refs; listen; history; text; internal format)
OFFSET

0,3

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

a(A135499(n)) = 0; a(A061470(n)) = 1. - Reinhard Zumkeller, Aug 08 2014

LINKS

Hieronymus Fischer, Table of n, a(n) for n = 0..10000

Jim Loy, Divisibility Tests

Stu Savory, Divisibility by prime numbers under 50

D. Sharpe and R. Webster, Reversing digits: divisibility by 27, 81, and 121, Mathematical Spectrum, 45 (2012/2013), 69-71.

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_{0<k<=m} (-1)^k*floor(n*b^(k-m-1)).

a(n) = (-1)^m*(n + (b+1)*sum_{k>0} (-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)

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 *)

PROG

(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]

(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

CROSSREFS

A055017 is closely related (but less natural).

Cf. A061479.

Cf. A004086.

Cf. A007953, A033999, A031298, A135499, A061470.

Cf. A257588.

Sequence in context: A241494 A076313 A055017 * A040997 A256851 A247149

Adjacent sequences:  A225690 A225691 A225692 * A225694 A225695 A225696

KEYWORD

sign,base,look

AUTHOR

N. J. A. Sloane, May 27 2013

EXTENSIONS

Comment corrected by Jens Kruse Andersen, Jul 13 2014

STATUS

approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recent
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified February 25 23:44 EST 2020. Contains 332270 sequences. (Running on oeis4.)