ACSL '09 Practice P3 - Zeroes

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 16M

Problem type
Allowed languages
Assembly, Brain****, C, C++, COBOL, Forth, Fortran, Java, Lua, Text, Turing
ACSL Practice 2009

The factorial of a positive integer n, written as n!, is the product of the first n positive integers. That is,

\displaystyle n! = 1 \times 2 \times \dots \times n

Given a positive integer n, find the number of zeros in the decimal representation of n!. Of course, leading zeros should not be counted. (Note that decimal representation means base ten representation.)

Example 1. There are 7 zeros in the decimal representation of 20!.

\displaystyle 20! = 1 \times 2 \times \dots \times 20 = 2432902008176640000

Example 2. There are 2 zeros in the decimal representation of 7!.

\displaystyle 7! = 1 \times 2 \times 3 \times 4 \times 5 \times 6 \times 7 = 5040

Example 3. There is no zero in the decimal representation of 4!.

\displaystyle 4! = 1 \times 2 \times 3 \times 4 = 24

Input Specification

The input contains a single positive integer n \le 100.

Output Specification

The number of zeros in the decimal representation of n!.

Sample Input 1

20

Sample Output 1

7

Sample Input 2

7

Sample Output 2

2

Sample Input 3

4

Sample Output 3

0

Comments


  • 0
    maxcruickshanks  commented on Jan. 15, 2022, 10:14 p.m.

    Since Java's BigInteger class is unintended and defeats the point of this problem, it has been disabled, and all Java submissions were rejudged.