login
This site is supported by donations to The OEIS Foundation.
Logo

Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A008904 Final nonzero digit of n!. 21
1, 1, 2, 6, 4, 2, 2, 4, 2, 8, 8, 8, 6, 8, 2, 8, 8, 6, 8, 2, 4, 4, 8, 4, 6, 4, 4, 8, 4, 6, 8, 8, 6, 8, 2, 2, 2, 4, 2, 8, 2, 2, 4, 2, 8, 6, 6, 2, 6, 4, 2, 2, 4, 2, 8, 4, 4, 8, 4, 6, 6, 6, 2, 6, 4, 6, 6, 2, 6, 4, 8, 8, 6, 8, 2, 4, 4, 8, 4, 6, 8, 8, 6, 8, 2, 2, 2, 4, 2, 8, 2, 2, 4, 2, 8, 6, 6, 2, 6 (list; graph; refs; listen; history; internal format)
OFFSET

0,3

COMMENTS

Jean-Paul Allouche (allouche(AT)math.jussieu.fr), Jul 25, 2001: this sequence is not ultimately periodic. This can be deduced from the fact that the sequence can be obtained as a fixed point of a morphism.

The decimal number .1126422428... formed from these digits is a transcendental number; see the article by G. Dresden. The Mathematica code uses Dresden's formula for the last nonzero digit of n!; this is more efficient than simply calculating n! and then taking its least-significant digit. - Greg Dresden (dresdeng(AT)wlu.edu), Feb 21 2006

Contribution from Robert G. Wilson v (rgwv(AT)rgwv.com), Feb 16 2011: (Start)

.(mod 10) == 2..........4..........6..........8

10^

...1.........4..........2..........1..........1

...2........28.........23.........22.........25

...3.......248........247........260........243

...4......2509.......2486.......2494.......2509

...5.....25026......24999......24972......25001

...6....249993.....250012.....250040.....249953

...7...2500003....2499972....2499945....2500078

...8..25000078...24999872...25000045...25000003

...9.249999807..250000018..250000466..249999707 (End)

REFERENCES

J.-P. Allouche and J. Shallit, Automatic Sequences, Cambridge Univ. Press, 2003, p. 202.

F. M. Dekking, Regularity and irregularity of sequences generated by automata, S\'em. Th\'eor. Nombres, Bordeaux, Expos\'e 9, 1979-1980, pages 9-01 to 9-10.

Gregory P. Dresden, Three transcendental numbers from the last non-zero digits of n^n, F_n and n!, Mathematics Magazine, pp. 96-105, vol. 81, 2008.

S. Kakutani, Ergodic theory of shift transformations, in Proc. 5th Berkeley Symp. Math. Stat. Prob., Univ. Calif. Press, vol. II, 1967, 405-414.

J. C. Martin, The structure of generalized Morse minimal sets on m symbols, Trans. Amer. Math. Soc. 232 (1977), 343-355.

LINKS

Robert G. Wilson v, (rgwv@rgwv.com), Table of n, a(n) for n = 0..10000 . [From Robert G. Wilson v (rgwv(AT)rgwv.com), May 20 2010]

W. Bomfim, An algorithm to find the last nonzero digit of n!

W. Bomfim, A property of the last non-zero digit of factorials

K. S. Brown, The least significant nonzero digit of n!

Gregory P. Dresden, Two Irrational Numbers ...

G. Dresden, Home page.

Fritz Jacob (fritzjacob(AT)gmail.com), A way to compute a(n)

MathPages, Least Significant Non-Zero Digit of n!

Eric Weisstein's World of Mathematics, Factorial

David W. Wilson, Minimal state machine for this sequence

David W. Wilson, Another method for computing this sequence

Index entries for sequences related to final digits of numbers

Index entries for sequences related to factorial numbers

FORMULA

The generating function for n>1 is as follows: for n = a_0 + 5 a_1 + 5^2 a_2 + ... +5^N a_N (the expansion of n in base-5), then the last nonzero digit of n!, for n>1, is 6*\prod_{i=0}^N (a_i)! (2^(i a_i)) mod 10 - Greg Dresden (dresdeng(AT)wlu.edu), Feb 21 2006

a(n) = f(n,1,0) with f(n,x,e) = if n<2 then A010879(x*A000079(e)) else f(n-1,A010879(x*A132740(n),e+A007814(n)-A112765(n)). [From Reinhard Zumkeller (reinhard.zumkeller(AT)gmail.com), Aug 16 2008]

a(0) = 1, a(1) = 1, if n >= 2, with

n represented in base 5 as (a_h, ... ,a_1,a_0)5,

t = sum{i = h, h-1, ... , 0} (a_i even),

x = sum{i=h, h-1, ... , 1}(sum{k=h, h-1, ... , i}(a_i)),

z = (x + t/2) mod 4, and y = 2^z,

a(n) = 6(y mod 2) + y(1-(y mod 2)).

For n >= 5, and n mod 5 = 0, i) a(n) = a(n+1) = a(n+3),   ii)   a(n+2)=2a(n) mod 10, and iii) a(n+4)=4a(n) mod 10.

For k not equal to 1, a(10^k) = a(2^k). See second Dresden link, and second Bomfim link.

[W. Bomfim webonfim(AT)bol.com Jan 09, 2011]

EXAMPLE

6! = 720, so a(6) = 2.

MATHEMATICA

f[n_]:=Module[{m=n!}, While[Mod[m, 10]==0, m=m/10]; Mod[m, 10]]

Table[f[i], {i, 0, 100}]

f[n_] := Mod[6Times @@ (Rest[FoldList[{ 1 + #1[[1]], #2!2^(#1[[1]]#2)} &, {0, 0}, Reverse[IntegerDigits[n, 5]]]]), 10][[2]]; Join[{1, 1}, Table[f[n], {n, 2, 100}]] (* program contributed by Jacob A. Siehler *) - Greg Dresden (dresdeng(AT)wlu.edu), Feb 21 2006

zOF[n_Integer?Positive] := Module[{maxpow=0}, While[5^maxpow<=n, maxpow++]; Plus@@Table[Quotient[n, 5^i], {i, maxpow-1}]]; Flatten[Table[Take[IntegerDigits[n!], {-zOF[n]-1}], {n, 100}]] [From Harvey P. Dale, Dec. 16, 2010]

PROG

(Python)  # replace triple dots by spaces

def a(n):

...if n<=1: return 1

...return 6*[1, 1, 2, 6, 4, 4, 4, 8, 4, 6][n%10]*3**(n/5%4)*a(n/5)%10

[From Maciej I. Wilczynski (maciej.i.wilczynski(AT)pwr.wroc.pl), Aug 23 2010]

(PARI) { a(n) = r=1; while(n>0, r *= Mod(4, 10)^((n\10)%2) * [1, 2, 6, 4, 2, 2, 4, 2, 8][max(n%10, 1)]; n\=5); lift(r) }

(Sage)

def A008904(n):

....# algorithm from David Wilson, http://oeis.org/A008904/a008904b.txt

....if n == 0 or n == 1: return 1

....dd = n.digits(base=5)

....x = sum(i*d for i, d in enumerate(dd))

....y = sum(d for d in dd if d % 2 == 0)/2

....z = 2**((x+y) % 4)

....if z == 1: z = 6

....return z # [D. S. McNeil, Dec 09 2010] (Haskell)

a008904 n = a008904_list !! n

a008904_list = 1 : 1 : f 2 1 where

   f n x = x' `mod` 10 : f (n+1) x' where

      x' = g (n * x) where

         g m | m `mod` 5 > 0 = m

             | otherwise     = g (m `div` 10)

-- Reinhard Zumkeller, Apr 08 2011

CROSSREFS

Cf. A008905, A000142.

Sequence in context: A059574 A004600 A021795 * A074382 A061350 A046276

Adjacent sequences:  A008901 A008902 A008903 * A008905 A008906 A008907

KEYWORD

nonn,base,nice

AUTHOR

Russ Cox (rsc(AT)swtch.com)

EXTENSIONS

More terms from Greg Dresden (dresdeng(AT)wlu.edu), Feb 21 2006

Pari code from Charles R Greathouse IV (charles.greathouse(AT)case.edu), Nov 05 2010

Pari code cleaned up by Max Alekseyev (maxale(AT)gmail.com), Jan 28 2012

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Transforms | Puzzles | Hot | Classics
Recent Additions | More pages | Superseeker | Maintained by The OEIS Foundation Inc.

Content is available under The OEIS End-User License Agreement .

Last modified February 13 06:53 EST 2012. Contains 205451 sequences.