Talk:Distribution of 0 digits in factorial series: Difference between revisions

m
(8 digits?)
 
 
(4 intermediate revisions by 3 users not shown)
Line 8:
 
--[[User:Chunes|Chunes]] ([[User talk:Chunes|talk]]) 04:46, 10 June 2021 (UTC)
 
An error, will correct this.
--[[User:Wherrera|Wherrera]] ([[User talk:Wherrera|talk]]) 05:23, 10 June 2021 (UTC)
 
 
== number of trailing zeros for factorials ==
 
In the Rosetta Code task preamble,   it states:
 
::: ''Because factorial numbers, which quickly become quite large, continue to have another terminal 0 on the right hand side of the number for every 5 increase in the factorial base number, one might think ...''
 
 
This is factually true, but understated.   In fact, another trailing zero is added for every increase in five, and for every   ''power of five''   as well.
 
So:
:*   for every increase in 5,   an additional trailing zero is added.
:* &nbsp; for every increase in 5<sup>2</sup>, an additional trailing zero is added.
:* &nbsp; for every increase in 5<sup>3</sup>, an additional trailing zero is added.
:* &nbsp; for every increase in 5<sup>4</sup>, an additional trailing zero is added.
:* &nbsp; for every increase in 5<sup>5</sup>, an additional trailing zero is added.
:* &nbsp; &nbsp; &nbsp; &bull;
:* &nbsp; &nbsp; &nbsp; &bull;
:* &nbsp; &nbsp; &nbsp; &bull;
 
 
Here is a simple REXX program than can calculate the number of trailing zeros. &nbsp; &nbsp; -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 18:14, 10 June 2021 (UTC)
<lang rexx>/*REXX program computes the number of trailing zeros in the factorial for any given N. */
numeric digits 100 /*just in case the user gets ka─razzzy.*/
parse arg N . /*obtain an optional argument from C.L.*/
if N=='' | N=="," then N= 1000000 /*Not specified? Then use the default.*/
z= 0 /*number of trailing zeroes (so far). */
v= 5 /*initialize V to five. */
do while v<=N /*calculate number of trailing zeroes. */
z= z + N % v /*bump Z if multiple power of five.*/
v= v * 5 /*calculate the next power of five. */
end /*while*/ /* [↑] % is REXX's integer division.*/
 
if z==0 then z= 'no' /*use gooder English for the message. */
say commas(N)'! has ' commas(z) " trailing zeroes."
exit z /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</lang>
Here is the output for the number of trailing zeros in the factorial of one million.
 
{{out|output|text=&nbsp; when using the input of: &nbsp; &nbsp; <tt> 10000000 </tt>}}
<pre>
1,000,000! has 249,998 trailing zeroes.
</pre>
 
True. So the number of terminal zeros actually goes up as the summation over [k from 1 to rounded up(log base 5 of n)] of (n / 5^k), ie n/5 + n/25 + n/125 .... Interesting, though the nonterminal part of n! still dominates the result eventually.
--[[User:Wherrera|Wherrera]] ([[User talk:Wherrera|talk]]) 18:27, 10 June 2021 (UTC)
10,327

edits