A027868 Number of trailing zeros in n!; highest power of 5 dividing n!.
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
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.
Links
- Hieronymus Fischer, Table of n, a(n) for n = 0..10000 (first 1000 terms from T. D. Noe)
- David S. Hart, James E. Marengo, Darren A. Narayan, and David S. Ross, On the number of trailing zeros in n!, College Math. J., 39(2):139-145, 2008.
- Enrique Pérez Herrero, Trailing Zeros in n!, Psychedelic Geometry Blogspot.
- Soichi Ikeda and Kaneaki Matsuoka, On transcendental numbers generated by certain integer sequences, Siauliai Math. Semin., 8 (16) 2013, 63-69.
- Shyam Sunder Gupta, Fascinating Factorials, Exploring the Beauty of Fascinating Numbers, Springer (2025) Ch. 16, 411-442.
- Shu-Chung Liu and Jean C.-C. Yeh, Catalan numbers modulo 2^k, J. Int. Seq. 13 (2010), 10.5.4, eq (5).
- Antonio M. Oller-Marcén, A new look at the trailing zeros of n!, arXiv:0906.4868v1 [math.NT], 2009.
- Antonio M. Oller-Marcén and J. Maria Grau, On the Base-b Expansion of the Number of Trailing Zeros of b^k!, J. Int. Seq. 14 (2011) 11.6.8
- Eric Weisstein's World of Mathematics, Factorial.
- Index entries for sequences related to factorial numbers
Crossrefs
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
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
Comments