of Number
Data Structures and Algorithms
Today we will be learning some important mathematical formulas and tricks that will help us in future
programming. Let us start with the factorial of a number. It is a straightforward process where we use an
integer to multiply n and, in every pass, we decrease n.
When we multiply a number by 10, it results in a trailing zero. In factorials, twos, and fives as a pair in a
number will result in the number of trailing zeros. For example, in the factorial of six (6!), there is only
one five and the number of twos is one, two, three, and four. So, at any point, the number of twos will
always be greater than the number of fives.
To find the number of fives in a factorial, we can use the formula: n/5 + n/25 + n/125 + ... (the list goes
on). For instance, let us say we want to find the number of trailing zeros in 10! We can use the formula
as follows:
10/5 + 10/25 = 2 + 0.4 = 2.4
Therefore, the number of trailing zeros in 10! is 2.
Now, you might be wondering how we can stop the process of finding the number of fives in a factorial.
We can stop it by adding 1 to all the numbers on the blackboard. For instance, if we have a variable
called "res," initially set to 0.5, "res" is the number that is just by itself (zero).
If "res" is less than 25, we must increase it by a multiple of 5 every time. But as soon as "res" becomes
more than n (the number we are finding the factorial of), we can break the loop.
To summarize, understanding the concept of factorials and how to find the number of trailing zeros is
crucial in programming. We can use the formula n/5 + n/25 + n/125 + ... to find the number of fives in a
factorial, and we can stop the process by adding 1 to all the numbers on the blackboard.