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.

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

This page as a plain text file.
%I A027868 #142 Aug 05 2025 17:42:30
%S A027868 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,
%T A027868 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,
%U A027868 14,14,14,14,14,15,15,15,15,15,16,16,16,16,16,18,18,18,18,18,19
%N A027868 Number of trailing zeros in n!; highest power of 5 dividing n!.
%C A027868 Also the highest power of 10 dividing n! (different from A054899). - _Hieronymus Fischer_, Jun 18 2007
%C A027868 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
%C A027868 Partial sums of A112765. - _Hieronymus Fischer_, Jun 06 2012
%C A027868 Also the number of trailing zeros in A000165(n) = (2*n)!!. - _Stefano Spezia_, Aug 18 2024
%D A027868 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.
%H A027868 Hieronymus Fischer, <a href="/A027868/b027868.txt">Table of n, a(n) for n = 0..10000</a> (first 1000 terms from T. D. Noe)
%H A027868 David S. Hart, James E. Marengo, Darren A. Narayan, and David S. Ross, <a href="http://www.jstor.org/stable/27646601">On the number of trailing zeros in n!</a>, College Math. J., 39(2):139-145, 2008.
%H A027868 Enrique Pérez Herrero, <a href="http://psychedelic-geometry.blogspot.com/2009/08/trailing-zeros-in-n.html">Trailing Zeros in n!</a>, Psychedelic Geometry Blogspot.
%H A027868 Soichi Ikeda and Kaneaki Matsuoka, <a href="https://web.archive.org/web/20180421062559id_/http://siauliaims.su.lt/pdfai/2013/Iked-Mats-2013.pdf">On transcendental numbers generated by certain integer sequences</a>, Siauliai Math. Semin., 8 (16) 2013, 63-69.
%H A027868 Shyam Sunder Gupta, <a href="https://doi.org/10.1007/978-981-97-2465-9_16">Fascinating Factorials</a>, Exploring the Beauty of Fascinating Numbers, Springer (2025) Ch. 16, 411-442.
%H A027868 Shu-Chung Liu and Jean C.-C. Yeh, <a href="https://cs.uwaterloo.ca/journals/JIS/VOL13/Liu2/liu6.html">Catalan numbers modulo 2^k</a>, J. Int. Seq. 13 (2010), 10.5.4, eq (5).
%H A027868 Antonio M. Oller-Marcén, <a href="http://arxiv.org/abs/0906.4868">A new look at the trailing zeros of n!</a>, arXiv:0906.4868v1 [math.NT], 2009.
%H A027868 Antonio M. Oller-Marcén and J. Maria Grau, <a href="https://cs.uwaterloo.ca/journals/JIS/VOL14/Oller/oller3.html">On the Base-b Expansion of the Number of Trailing Zeros of b^k!</a>, J. Int. Seq. 14 (2011) 11.6.8
%H A027868 Eric Weisstein's World of Mathematics, <a href="https://mathworld.wolfram.com/Factorial.html">Factorial</a>.
%H A027868 <a href="/index/Fa#factorial">Index entries for sequences related to factorial numbers</a>
%F A027868 a(n) = Sum_{i>=1} floor(n/5^i).
%F A027868 a(n) = (n - A053824(n))/4.
%F A027868 From _Hieronymus Fischer_, Jun 25 2007 and Aug 13 2007, edited by _M. F. Hasler_, Dec 27 2019: (Start)
%F A027868 G.f.: g(x) = Sum_{k>0} x^(5^k)/(1-x^(5^k))/(1-x).
%F A027868 a(n) = Sum_{k=5..n} Sum_{j|k, j>=5} (floor(log_5(j)) - floor(log_5(j-1))).
%F A027868 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.
%F A027868 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)).
%F A027868 Recurrence:
%F A027868 a(n) = floor(n/5) + a(floor(n/5));
%F A027868 a(5*n) = n + a(n);
%F A027868 a(n*5^m) = n*(5^m-1)/4 + a(n).
%F A027868 a(k*5^m) = k*(5^m-1)/4, for 0 <= k < 5, m >= 0.
%F A027868 Asymptotic behavior:
%F A027868 a(n) = n/4 + O(log(n)),
%F A027868 a(n+1) - a(n) = O(log(n)), which follows from the inequalities below.
%F A027868 a(n) <= (n-1)/4; equality holds for powers of 5.
%F A027868 a(n) >= n/4 - 1 - floor(log_5(n)); equality holds for n = 5^m-1, m > 0.
%F A027868 lim inf (n/4 - a(n)) = 1/4, for n -> oo.
%F A027868 lim sup (n/4 - log_5(n) - a(n)) = 0, for n -> oo.
%F A027868 lim sup (a(n+1) - a(n) - log_5(n)) = 0, for n -> oo.
%F A027868 (End)
%F A027868 a(n) <= A027869(n). - _Reinhard Zumkeller_, Jan 27 2008
%F A027868 10^a(n) = A000142(n) / A004154(n). - _Reinhard Zumkeller_, Nov 24 2012
%F A027868 a(n) = Sum_{k=1..floor(n/2)} floor(log_5(n/k)). - _Ammar Khatab_, Feb 01 2025
%e A027868 a(100)  = 24.
%e A027868 a(10^3) = 249.
%e A027868 a(10^4) = 2499.
%e A027868 a(10^5) = 24999.
%e A027868 a(10^6) = 249998.
%e A027868 a(10^7) = 2499999.
%e A027868 a(10^8) = 24999999.
%e A027868 a(10^9) = 249999998.
%e A027868 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
%p A027868 0, seq(add(floor(n/5^i),i=1..floor(log[5](n))), n=1..100); # _Robert Israel_, Nov 13 2014
%t A027868 Table[t = 0; p = 5; While[s = Floor[n/p]; t = t + s; s > 0, p *= 5]; t, {n, 0, 100} ]
%t A027868 Table[ IntegerExponent[n!], {n, 0, 80}] (* _Robert G. Wilson v_ *)
%t A027868 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 *)
%o A027868 (Haskell)
%o A027868 a027868 n = sum $ takeWhile (> 0) $ map (n `div`) $ tail a000351_list
%o A027868 -- _Reinhard Zumkeller_, Oct 31 2012
%o A027868 (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
%o A027868 (PARI) a(n)=valuation(n!,5) \\ _Charles R Greathouse IV_, Nov 08 2012
%o A027868 (PARI) apply( A027868(n)=(n-sumdigits(n,5))\4, [0..99]) \\ _M. F. Hasler_, Dec 27 2019
%o A027868 (Python)
%o A027868 from sympy import multiplicity
%o A027868 A027868, p5 = [0,0,0,0,0], 0
%o A027868 for n in range(5,10**3,5):
%o A027868     p5 += multiplicity(5,n)
%o A027868     A027868.extend([p5]*5) # _Chai Wah Wu_, Sep 05 2014
%o A027868 (Python)
%o A027868 def A027868(n): return 0 if n<5 else n//5 + A027868(n//5) # _David Radcliffe_, Jun 26 2016
%o A027868 (Python)
%o A027868 from sympy.ntheory.factor_ import digits
%o A027868 def A027868(n): return n-sum(digits(n,5)[1:])>>2 # _Chai Wah Wu_, Oct 18 2024
%o A027868 (Magma) [Valuation(Factorial(n), 5): n in [0..80]]; // _Bruno Berselli_, Oct 11 2021
%Y A027868 See A000966 for the missing numbers. See A011371 and A054861 for analogs involving powers of 2 and 3.
%Y A027868 Cf. A054899, A007953, A112765, A067080, A098844, A132027, A067080, A098844, A132029, A054999, A112765, A191610, A000351.
%Y A027868 Cf. also A000142, A004154.
%Y A027868 Cf. A000165, A008904.
%K A027868 nonn,base,nice,easy
%O A027868 0,11
%A A027868 _Warut Roonguthai_
%E A027868 Examples added by _Hieronymus Fischer_, Jun 06 2012