Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Trailing Zeros in Factorial
MEDIUM
15 mins
27 upvotes
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Trailing Zeros in Factorial

Contributed by
Dhruv Sharma
Medium
yellow-spark
0/80
Avg time to solve 15 mins
Success Rate 80 %
Share
27 upvotes

Problem Statement

You are given an integer N, you need to find the number of trailing zeroes in N! (N factorial).

Note:

1. Trailing zeros in a number can be defined as the number of continuous suffix zeros starting from the zeroth place of a number.
2. For example, if a number X = 1009000, then the number of trailing zeros = 3 where the zeroth place is 0, the tenth place is 0, the hundredth place is 0.
3. ! means “FACTORIAL”. Factorial of a number is calculated by the product of the integer and all integers below it till 1.
4. Value of 0! is 1.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
1
5
Sample Output 1:
1
Explanation for Sample Input 1:
The value of 5! is calculated as 5 * 4 * 3 * 2 * 1 = 120. 120 has 1 trailing zero.
Sample Input 2:
2
3
2147
Sample Output 2:
0
534
Reset Code
Full screen
Auto
copy-code
Console