Function Resource

Function Repository Resource:

TrailingZeroes

Source Notebook

Calculate the number of trailing zeroes at the end of the factorial of a number

Contributed by: Peter Cullen Burbery

ResourceFunction["TrailingZeroes"][n]

finds the number of trailing zeroes at the end of the factorial of n.

Examples

Basic Examples (9) 

Find the number of factorials in the ceiling of ⅇ to the 100:

In[1]:=
ResourceFunction[
CloudObject[ "https://www.wolframcloud.com/obj/burbery1/DeployedResources/Function/TrailingZeroes"]][Ceiling[E^100]]
Out[1]=

This number is too large to compute the factorial for exactly:

In[2]:=
Ceiling[E^100]
Out[2]=

We effectively found the number of trailing zeroes in the number ⌈ⅇ100⌉! =26881171418161354484126255515800135873611119!.

When I was a student at the West Virginia 2018 State Math Field Day in 10th Grade at Marshall University there was a problem my team for Huntington High School had to solve together to find I think the number of zeroes in 2018! Find the answer:

In[3]:=
ResourceFunction[
CloudObject[ "https://www.wolframcloud.com/obj/burbery1/DeployedResources/Function/TrailingZeroes"]][2018]
Out[3]=

Calculate the number of trailing zeroes of 10! in base 12:

In[4]:=
ResourceFunction[
CloudObject[ "https://www.wolframcloud.com/obj/burbery1/DeployedResources/Function/TrailingZeroes"]][10, 12]
Out[4]=

Find the number of trailing zeros of 100! in base 45:

In[5]:=
ResourceFunction[
CloudObject[ "https://www.wolframcloud.com/obj/burbery1/DeployedResources/Function/TrailingZeroes"]][100, 45]
Out[5]=

Find the number of trailing zeros in the base-17 representation of 2017!:

In[6]:=
ResourceFunction[
CloudObject[ "https://www.wolframcloud.com/obj/burbery1/DeployedResources/Function/TrailingZeroes"]][2017, 17]
Out[6]=

Find the number of trailing zeros in the base-18 representation of 2018!:

In[7]:=
ResourceFunction[
CloudObject[ "https://www.wolframcloud.com/obj/burbery1/DeployedResources/Function/TrailingZeroes"]][2018, 18]
Out[7]=

Find the smallest integer N such that when N! is written in base 12, it has 121 trailing zeros. Enter your answer in base 6:

In[8]:=
BaseForm[NestWhile[# + 1 &, 2, (ResourceFunction[
CloudObject[ "https://www.wolframcloud.com/obj/burbery1/DeployedResources/Function/TrailingZeroes"]][#, 12] < 121) &], 6]
Out[8]=

Let 3a be the highest power of 3 that divides 1000!. What is a? Source: Floor and Ceiling Functions: Level 2 Challenges Question 5

In[9]:=
ResourceFunction[
CloudObject[ "https://www.wolframcloud.com/obj/burbery1/DeployedResources/Function/TrailingZeroes"]][1000, 3]
Out[9]=

Source Metadata

Author Notes

I added the ability to compute in bases other than 10 in the future based on the Brilliant Wiki article.