Trailing Zeros in Factorial

 Count The Trailing Zeros in Factorial

Given an integer n, find the number of trailing 0s in its factorial. Do this without actually finding the n!, as the integer given can be large and its factorial can exceed the integer limits.

Input format :

Integer n  

Output Format :

Count of trailing 0s

Constraints :

1 <= n <= 10^11

Sample Input

50

Sample Output

12   
C++ Code:
#include <iostream>
using namespace std;

int main()
{
	int n,c=0;
	cin>>n;
	for(int i=5; n/i>=1; i*=5)
	{
		 c += n/i;
		 
	}
	cout << c ;
	
}

SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment