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

A027868 Number of trailing zeros in n!; highest power of 5 dividing n!.

Original entry on oeis.org

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

Views

Author

Keywords

Comments

Also the highest power of 10 dividing n! (different from A054899). - Hieronymus Fischer, Jun 18 2007
Alternatively, a(n) equals the expansion of the base-5 representation A007091(n) of n (i.e., where successive positions from right to left stand for 5^n or A000351(n)) under a scale of notation whose successive positions from right to left stand for (5^n - 1)/4 or A003463(n); for instance, n = 7392 has base-5 expression 2*5^5 + 1*5^4 + 4*5^3 + 0*5^2 + 3*5^1 + 2*5^0, so that a(7392) = 2*781 + 1*156 + 4*31 + 0*6 + 3*1 + 2*0 = 1845. - Lekraj Beedassy, Nov 03 2010
Partial sums of A112765. - Hieronymus Fischer, Jun 06 2012
Also the number of trailing zeros in A000165(n) = (2*n)!!. - Stefano Spezia, Aug 18 2024

Examples

			a(100)  = 24.
a(10^3) = 249.
a(10^4) = 2499.
a(10^5) = 24999.
a(10^6) = 249998.
a(10^7) = 2499999.
a(10^8) = 24999999.
a(10^9) = 249999998.
a(10^n) = 10^n/4 - 3 for 10 <= n <= 15 except for a(10^14) = 10^14/4 - 2. - _M. F. Hasler_, Dec 27 2019
		

References

  • M. Gardner, "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, 1978, pp. 50-65.

Crossrefs

See A000966 for the missing numbers. See A011371 and A054861 for analogs involving powers of 2 and 3.
Cf. also A000142, A004154.

Programs

  • Haskell
    a027868 n = sum $ takeWhile (> 0) $ map (n `div`) $ tail a000351_list
    -- Reinhard Zumkeller, Oct 31 2012
    
  • Magma
    [Valuation(Factorial(n), 5): n in [0..80]]; // Bruno Berselli, Oct 11 2021
  • Maple
    0, seq(add(floor(n/5^i),i=1..floor(log[5](n))), n=1..100); # Robert Israel, Nov 13 2014
  • Mathematica
    Table[t = 0; p = 5; While[s = Floor[n/p]; t = t + s; s > 0, p *= 5]; t, {n, 0, 100} ]
    Table[ IntegerExponent[n!], {n, 0, 80}] (* Robert G. Wilson v *)
    zOF[n_Integer?Positive]:=Module[{maxpow=0},While[5^maxpow<=n,maxpow++];Plus@@Table[Quotient[n,5^i],{i,maxpow-1}]]; Attributes[zOF]={Listable}; Join[{0},zOF[ Range[100]]] (* Harvey P. Dale, Apr 11 2022 *)
  • PARI
    a(n)={my(s);while(n\=5,s+=n);s} \\ Charles R Greathouse IV, Nov 08 2012, edited by M. F. Hasler, Dec 27 2019
    
  • PARI
    a(n)=valuation(n!,5) \\ Charles R Greathouse IV, Nov 08 2012
    
  • PARI
    apply( A027868(n)=(n-sumdigits(n,5))\4, [0..99]) \\ M. F. Hasler, Dec 27 2019
    
  • Python
    from sympy import multiplicity
    A027868, p5 = [0,0,0,0,0], 0
    for n in range(5,10**3,5):
        p5 += multiplicity(5,n)
        A027868.extend([p5]*5) # Chai Wah Wu, Sep 05 2014
    
  • Python
    def A027868(n): return 0 if n<5 else n//5 + A027868(n//5) # David Radcliffe, Jun 26 2016
    
  • Python
    from sympy.ntheory.factor_ import digits
    def A027868(n): return n-sum(digits(n,5)[1:])>>2 # Chai Wah Wu, Oct 18 2024
    

Formula

a(n) = Sum_{i>=1} floor(n/5^i).
a(n) = (n - A053824(n))/4.
From Hieronymus Fischer, Jun 25 2007 and Aug 13 2007, edited by M. F. Hasler, Dec 27 2019: (Start)
G.f.: g(x) = Sum_{k>0} x^(5^k)/(1-x^(5^k))/(1-x).
a(n) = Sum_{k=5..n} Sum_{j|k, j>=5} (floor(log_5(j)) - floor(log_5(j-1))).
G.f.: g(x) = 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 5, else b(k) = 0.
G.f.: g(x) = Sum_{k>0} c(k)*x^k/(1-x), where c(k) = Sum_{j>1, j|k} floor(log_5(j)) - floor(log_5(j - 1)).
Recurrence:
a(n) = floor(n/5) + a(floor(n/5));
a(5*n) = n + a(n);
a(n*5^m) = n*(5^m-1)/4 + a(n).
a(k*5^m) = k*(5^m-1)/4, for 0 <= k < 5, m >= 0.
Asymptotic behavior:
a(n) = n/4 + O(log(n)),
a(n+1) - a(n) = O(log(n)), which follows from the inequalities below.
a(n) <= (n-1)/4; equality holds for powers of 5.
a(n) >= n/4 - 1 - floor(log_5(n)); equality holds for n = 5^m-1, m > 0.
lim inf (n/4 - a(n)) = 1/4, for n -> oo.
lim sup (n/4 - log_5(n) - a(n)) = 0, for n -> oo.
lim sup (a(n+1) - a(n) - log_5(n)) = 0, for n -> oo.
(End)
a(n) <= A027869(n). - Reinhard Zumkeller, Jan 27 2008
10^a(n) = A000142(n) / A004154(n). - Reinhard Zumkeller, Nov 24 2012
a(n) = Sum_{k=1..floor(n/2)} floor(log_5(n/k)). - Ammar Khatab, Feb 01 2025

Extensions

Examples added by Hieronymus Fischer, Jun 06 2012

A004154 a(n) = n! with trailing zeros omitted.

Original entry on oeis.org

1, 1, 2, 6, 24, 12, 72, 504, 4032, 36288, 36288, 399168, 4790016, 62270208, 871782912, 1307674368, 20922789888, 355687428096, 6402373705728, 121645100408832, 243290200817664, 5109094217170944, 112400072777760768, 2585201673888497664, 62044840173323943936
Offset: 0

Views

Author

Keywords

Crossrefs

Cf. A000142, A004151, A008904 (mod 10).

Programs

  • Haskell
    a004154 = a004151 . a000142
    a004154_list = scanl (\u v -> a004151 $ u * v) 1 [1..]
    -- Reinhard Zumkeller, Nov 24 2012
    
  • Magma
    [Factorial(n)/10^Valuation(Factorial(n), 5): n in [0..30]]; // Vincenzo Librandi, Oct 16 2014
    
  • Maple
    a:= n-> (f-> f/10^padic[ordp](f,10))(n!):
    seq(a(n), n=0..29);  # Alois P. Heinz, Dec 29 2021
  • Mathematica
    Array[#!//.x_/;x~Mod~5==0:>x/10&,22]  (* Giorgos Kalogeropoulos, Aug 17 2020 *)
    Join[{1,1,2,6,24},Table[FromDigits[Flatten[Most[Split[IntegerDigits[n!]]]]],{n,5,30}]] (* or *) Table[n!/10^IntegerExponent[n!,10],{n,0,30}] (* Harvey P. Dale, Feb 13 2024 *)
  • PARI
    a(n)=n!/10^valuation(n!,5) \\ M. F. Hasler, Oct 16 2014
    
  • Python
    from sympy import factorial
    from sympy.ntheory.factor_ import digits
    def A004154(n): return factorial(n)//10**(n-sum(digits(n,5)[1:])>>2) # Chai Wah Wu, Oct 18 2024
    
  • Python
    from itertools import count, islice
    def agen(): # generator of terms
        f = 1
        for n in count(1):
            yield f
            while n%10 == 0: n //= 10
            f *= n
            while f%10 == 0: f //= 10
    print(list(islice(agen(), 25))) # Michael S. Branicky, Apr 11 2025

Formula

a(n) = A000142(n) / 10^A027868(n). - Reinhard Zumkeller, Nov 24 2012
a(n+1) = A004151((n+1)*a(n)). - Reinhard Zumkeller, Nov 24 2012, corrected by M. F. Hasler, Oct 16 2014
a(n) = A004151(A000142(n)) = A000142(n)/A011557(A112765(n)), or A122840 instead of A112765. - M. F. Hasler, Oct 16 2014

A136690 Final nonzero digit of n! in base 3.

Original entry on oeis.org

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

Views

Author

Carl R. White, Jan 16 2008

Keywords

Examples

			6! = 720 decimal = 222200 ternary, so a(6) = 2.
		

Crossrefs

Programs

  • Mathematica
    f[n_] := Mod[6 Times @@ (Rest[ FoldList[{1 + #1[[1]], #2! 2^(#1[[1]] #2)} &, {0, 0}, Reverse[ IntegerDigits[n, 3]]]]), 10][[2]]; # /. {0 -> 1} & /@ Mod[Table[f@n, {n, 0, 104}], 3] (* Robert G. Wilson v, Apr 17 2010 *)
    fnzd[n_]:=Module[{sidn3=Split[IntegerDigits[n!,3]]},If[MemberQ[ Last[ sidn3],0], sidn3[[-2,1]], sidn3[[-1,1]]]]; Array[fnzd,110,0] (* Harvey P. Dale, May 03 2018 *)
  • PARI
    a(n) = vecsum([bittest(220,b) |b<-digits(n,9)])%2 + 1; \\ Kevin Ryde, Dec 03 2022

Formula

From David Radcliffe, Sep 03 2021: (Start)
a(n) = (n! / A060828(n)) mod 3;
a(n) = 1 + (A189672(n) mod 2);
a(6*n) = a(6*n+1) = a(2*n);
a(6*n+2) = 3 - a(2*n);
a(6*n+3) = a(6*n+4) = 3 - a(2*n+1);
a(6*n+5) = a(2*n+1).
(End)
a(n) = A008904(A127110(n)). - Michel Marcus, Sep 04 2021
From Kevin Ryde, Dec 03 2022: (Start)
a(n) = 1 if n written in base 9 has an even number of digits {2,3,4,6,7}; and otherwise a(n) = 2.
Fixed point of the morphism 1 -> 1,1,2,2,2,1,2,2,1; 2 -> 2,2,1,1,1,2,1,1,2; starting from 1.
(End)
a(n) = A212307(n) mod 3. - Ridouane Oudra, Sep 25 2024

Extensions

More terms from Robert G. Wilson v, Apr 17 2010

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

Showing 1-10 of 31 results. Next