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 15 results. Next

A008904 a(n) is the final nonzero digit of n!.

Original entry on oeis.org

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
Offset: 0

Views

Author

Keywords

Comments

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. - Jean-Paul Allouche, Jul 25 2001
The decimal number 0.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, Feb 21 2006
From Robert G. Wilson v, 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)

Examples

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

References

  • J.-P. Allouche and J. Shallit, Automatic Sequences, Cambridge Univ. Press, 2003, p. 202.
  • Gardner, M. "Factorial Oddities." Ch. 4 in Mathematical Magic Show: More Puzzles, Games, Diversions, Illusions and Other Mathematical Sleight-of-Mind from Scientific American. New York: Vintage, pp. 50-65, 1978
  • S. Kakutani, Ergodic theory of shift transformations, in Proc. 5th Berkeley Symp. Math. Stat. Prob., Univ. Calif. Press, vol. II, 1967, 405-414.
  • Popular Computing (Calabasas, CA), Problem 120, Factorials, Vol. 4 (No. 36, Mar 1976), page PC36-3.

Crossrefs

Programs

  • 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
  • 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, 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}]] (* Harvey P. Dale, Dec 16 2010 *)
    f[n_]:=Block[{id=IntegerDigits[n!, 10]}, While[id[[-1]]==0, id=Most@id]; id[[-1]]]; Table[f@n, {n, 0, 100}] (* Vincenzo Librandi, Sep 07 2017 *)
  • 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) \\ Charles R Greathouse IV, Nov 05 2010; cleaned up by Max Alekseyev, Jan 28 2012
    
  • Python
    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
    # Maciej Ireneusz Wilczynski, Aug 23 2010
    
  • Python
    from functools import reduce
    from sympy.ntheory.factor_ import digits
    def A008904(n): return reduce(lambda x,y:x*y%10,(((6,2,4,8,6,2,4,8,2,4,8,6,6,2,4,8,4,8,6,2)[(a<<2)|(i*a&3)] if i*a else (1,1,2,6,4)[a]) for i, a in enumerate(digits(n,5)[-1:0:-1])),6) if n>1 else 1 # Chai Wah Wu, Dec 07 2023
    
  • 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
    

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*Product_{i=0..N} (a_i)! (2^(i a_i)) mod 10. - Greg Dresden, 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)). - Reinhard Zumkeller, Aug 16 2008
From Washington Bomfim, Jan 09 2011: (Start)
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) = 2*a(n) mod 10, and
iii) a(n+4) = 4*a(n) mod 10.
For k not equal to 1, a(10^k) = a(2^k). See second Dresden link, and second Bomfim link.
(End)

Extensions

More terms from Greg Dresden, Feb 21 2006

A136691 Final nonzero digit of n! in base 4.

Original entry on oeis.org

1, 1, 2, 2, 2, 2, 1, 3, 2, 2, 3, 1, 3, 3, 2, 2, 2, 2, 3, 1, 1, 1, 2, 2, 3, 3, 2, 2, 2, 2, 1, 3, 2, 2, 3, 1, 1, 1, 2, 2, 1, 1, 2, 2, 2, 2, 3, 1, 3, 3, 2, 2, 2, 2, 3, 1, 2, 2, 3, 1, 3, 3, 2, 2, 2, 2, 3, 1, 1, 1, 2, 2, 1, 1, 2, 2, 2, 2, 3, 1, 1, 1, 2, 2, 2, 2, 1, 3, 2, 2, 1, 3, 1, 1, 2, 2, 3, 3, 2, 2
Offset: 0

Views

Author

Carl R. White, Jan 16 2008

Keywords

Examples

			6! = 720 decimal = 23100 quartal, so a(6) = 1.
		

Crossrefs

Programs

  • Mathematica
    nzd[n_]:=Module[{rd=RealDigits[n!,4][[1]]},If[Last[rd]!=0,Last[rd], Last[ Flatten[Most[Split[rd]]]]]]; Array[nzd,100,0] (* Harvey P. Dale, May 08 2014 *)

A136695 Final nonzero digit of n! in base 8.

Original entry on oeis.org

1, 1, 2, 6, 3, 7, 2, 6, 6, 6, 4, 4, 6, 6, 4, 4, 3, 3, 6, 2, 5, 1, 6, 2, 6, 6, 4, 4, 6, 6, 4, 4, 6, 6, 4, 4, 2, 2, 4, 4, 4, 4, 1, 3, 4, 4, 3, 5, 6, 6, 4, 4, 2, 2, 4, 4, 4, 4, 3, 1, 4, 4, 5, 3, 3, 3, 6, 2, 1, 5, 6, 2, 2, 2, 4, 4, 2, 2, 4, 4, 5, 5, 2, 6, 3, 7, 2, 6, 2, 2, 4, 4, 2, 2, 4, 4, 6, 6, 4, 4
Offset: 0

Views

Author

Carl R. White, Jan 16 2008

Keywords

Examples

			6! = 720 decimal = 1320 octal, so a(6) = 2.
		

Crossrefs

Programs

  • Maple
    P:= 1: E:= 0: a[0]:= 1:
    for n from 1 to 100 do
      v:= padic:-ordp(n,2);
      P:= P*(n/2^v) mod 8;
      E:= E + v;
      if E mod 3 = 0 then a[n]:= P
      elif E mod 3 = 1 then a[n]:= 2*(P mod 4)
      else a[n]:= 4
      fi
    od:
    seq(a[n],n=0..100); # Robert Israel, Sep 26 2018
  • Mathematica
    Table[IntegerDigits[FromDigits[Reverse[IntegerDigits[n!,8]]]][[1]],{n,0,100}] (* Harvey P. Dale, Nov 29 2024 *)

Formula

From Robert Israel, Sep 26 2018: (Start)
If A011371(n) == 0 (mod 3) then a(n) = A049606(n) mod 8.
If A011371(n) == 1 (mod 3) then a(n) = 2*(A049606(n) mod 4).
If A011371(n) == 2 (mod 3) then a(n) = 4. (End)

A136698 Final nonzero digit of n! in base 12.

Original entry on oeis.org

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

Views

Author

Carl R. White, Jan 16 2008

Keywords

Comments

The asymptotic densities of the numbers k such that a(k) = m is 1/2 for m = 4 or 8, and 0 otherwise (Deshouillers and Ruzsa, 2011). Therefore, the asymptotic mean of this sequence is 6. There are infinitely many numbers k such that a(k) = m for each of the values m = 3, 6, or 9 (Deshouillers, 2012). - Amiram Eldar, Jan 11 2021

Examples

			6! = 720 decimal = 500 duodecimal, so a(6) = 5.
		

Crossrefs

Programs

  • Mathematica
    a136698[n_Integer] := Last[Select[IntegerDigits[n!, 12], # > 0 &]]; a136698 /@ Range[0, 144] (* Michael De Vlieger, Aug 13 2014 *)
  • PARI
    a(n) = my(d=digits(n!, 12)); forstep(k=#d, 1, -1, if (d[k], return(d[k]))); \\ Michel Marcus, Feb 18 2025

A136692 Final nonzero digit of n! in base 5.

Original entry on oeis.org

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

Views

Author

Carl R. White, Jan 16 2008

Keywords

Examples

			6! = 720 decimal = 10340 quinary, so a(6) = 4.
		

Crossrefs

Programs

  • Maple
    f:= proc(n) option remember;
       local t;
       t:= n / 5^padic:-ordp(n,5);
       procname(n-1)*t mod 5
    end proc:
    f(0):= 1:
    map(f, [$0..100]); # Robert Israel, Jun 27 2025
  • Mathematica
    Table[Module[{sp=Split[IntegerDigits[n!,5]]},If[sp[[-1,-1]]==0,sp[[-2, -1]], sp[[-1,-1]]]],{n,0,100}] (* Harvey P. Dale, Oct 26 2016 *)
  • PARI
    a(n)={my(v=[1, 1, 2, 1, 4, 4, 4, 3, 4, 1]); if(n==0, 1, lift(prod(k=0, logint(n,5), Mod(v[1 + n\5^k % 10], 5))))} \\ Andrew Howroyd, Sep 27 2024

Formula

a(n) = (n!/A243757(n)) mod 5. - Ridouane Oudra, Sep 27 2024

A136694 Final nonzero digit of n! in base 7.

Original entry on oeis.org

1, 1, 2, 6, 3, 1, 6, 6, 6, 5, 1, 4, 6, 1, 2, 2, 4, 5, 6, 2, 5, 1, 1, 2, 6, 3, 1, 6, 3, 3, 6, 4, 2, 3, 4, 6, 6, 5, 1, 4, 6, 1, 6, 6, 5, 1, 4, 6, 1, 1, 1, 2, 6, 3, 1, 6, 6, 6, 5, 1, 4, 6, 1, 2, 2, 4, 5, 6, 2, 5, 1, 1, 2, 6, 3, 1, 6, 3, 3, 6, 4, 2, 3, 4, 6, 6, 5, 1, 4, 6, 1, 6, 6, 5, 1, 4, 6, 1, 2, 2
Offset: 0

Views

Author

Carl R. White, Jan 16 2008

Keywords

Examples

			6! = 720 decimal = 2046 septimal, so a(6) = 6.
		

Crossrefs

A136696 Final nonzero digit of n! in base 9.

Original entry on oeis.org

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

Views

Author

Carl R. White, Jan 16 2008

Keywords

Examples

			6! = 720 decimal = 880 nonary, so a(6) = 8.
		

Crossrefs

A136697 Final nonzero digit of n! in base 11.

Original entry on oeis.org

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

Views

Author

Carl R. White, Jan 16 2008

Keywords

Examples

			6! = 720 decimal = 5A5 undecimal, so a(6) = 5.
		

Crossrefs

A136699 Final nonzero digit of n! in base 13.

Original entry on oeis.org

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

Views

Author

Carl R. White, Jan 16 2008

Keywords

Examples

			6! = 720 decimal = 435 tridecimal, so a(6) = 5.
		

Crossrefs

Programs

  • Mathematica
    f[s_List] := Block[{a = s[[ -1]], len = Length@s}, Append[s, If[Mod[len, 13] == 0, Mod[a*len/13,13], Mod[a*len, 13]]]]; Nest[f, {1}, 100] (* Robert G. Wilson v, May 03 2009 *)
    f[n_] := Block[{id = IntegerDigits[n!, 13]}, While[id[[ -1]] == 0, id = Most@id]; id[[ -1]]]; Table[ f@n, {n, 0, 100}] (* Robert G. Wilson v, May 03 2009 *)

A136701 Final nonzero digit of n! in base 15.

Original entry on oeis.org

1, 1, 2, 6, 9, 8, 3, 6, 3, 12, 3, 3, 6, 3, 12, 12, 12, 9, 12, 3, 9, 9, 3, 9, 6, 9, 9, 3, 9, 6, 12, 12, 9, 12, 3, 12, 12, 9, 12, 3, 3, 3, 6, 3, 12, 6, 6, 12, 6, 9, 12, 12, 9, 12, 3, 6, 6, 12, 6, 9, 6, 6, 12, 6, 9, 9, 9, 3, 9, 6, 3, 3, 6, 3, 12, 9, 9, 3, 9, 6, 12, 12, 9, 12, 3, 12, 12, 9, 12, 3, 3, 3, 6
Offset: 0

Views

Author

Carl R. White, Jan 16 2008

Keywords

Comments

From Robert Israel, Jun 08 2018: (Start)
For n >= 6, a(n) is 3, 6, 9 or 12.
For k >= 2, a(5*k) = a(5*k+1) = a(5*k+3). (End)

Examples

			6! = 720 decimal = 330 quindecimal, so a(6) = 3.
		

Crossrefs

Programs

  • Maple
    a:= 1: b:= 0: R[0]:= 1:
    for n from 1 to 100 do
       alpha:= padic:-ordp(n,3);
       beta:= padic:-ordp(n,5);
       a:= a * n/3^alpha/5^beta;
       b:= b + alpha - beta;
       R[n]:= a * 3 &^ b mod 15;
    od:
    seq(R[n],n=0..100); # Robert Israel, Jun 08 2018
  • Mathematica
    nzd[x_]:=If[x[[-1,1]]==0,x[[-2,1]],x[[-1,1]]]; Table[nzd[Split[IntegerDigits[n!,15]]],{n,0,100}] (* Harvey P. Dale, Jul 11 2023 *)
Showing 1-10 of 15 results. Next