Trailing Zeros in Factorial
Python
Medium
5 views
Problem Description
Read n, find how many trailing zeros are in n factorial. Use loop dividing by 5.
Input Format
One integer n.
Output Format
One integer zeros.
Official Solution
import sys
s=sys.stdin.read().strip()
if not s: sys.exit(0)
n=int(s)
cnt=0
p=5
while p<=n:
cnt+=n//p
p*=5
sys.stdout.write(str(cnt))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!