Talk:Distribution of 0 digits in factorial series: Difference between revisions
Content added Content deleted
No edit summary |
(added a section header for a new talk section concerning the number of trailing zeros in a factorial product.) |
||
Line 11: | Line 11: | ||
An error, will correct this. |
An error, will correct this. |
||
--[[User:Wherrera|Wherrera]] ([[User talk:Wherrera|talk]]) 05:23, 10 June 2021 (UTC) |
--[[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. |
|||
:* for every increase in 5<sup>2</sup>, an additional trailing zero is added. |
|||
:* for every increase in 5<sup>3</sup>, an additional trailing zero is added. |
|||
:* for every increase in 5<sup>4</sup>, an additional trailing zero is added. |
|||
:* for every increase in 5<sup>5</sup>, an additional trailing zero is added. |
|||
:* • |
|||
:* • |
|||
:* • |
|||
Here is a simple REXX program than can calculate the number of trailing zeros. -- [[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= when using the input of: <tt> 10000000 </tt>}} |
|||
<pre> |
|||
1,000,000! has 249,998 trailing zeroes. |
|||
</pre> |