Smallest number n, having k trailing zeros in n! (LightOJ – 1138)

Problem Link: LightOJ 1138

We can easily calculate trailing zeros in n!. But, this problem refers to find the smallest n where n! holds exactly k trailing zeros.

If you don’t know how to calculate trailing zeros of n!. Read here – Trailing Zeros.

The max range is 10^8. So, 5*10^8! can hold this amount of trailing zero ( using only 5^1 factors ). As, the number of trailing zero increases with the increment of n. Now, search for n and check if that contains k trailing zero or not. Factorial of multiple numbers can contain same numbers of trailing zero, in this problem you just have to find the smallest one, which is obviously a multiple of 5. Now, code it and have a green verdict…

Code:

“For every complex problem there is an answer that is clear, simple, and wrong

H. L. Mencken

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website at WordPress.com
Get started
%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close