Cod sursa(job #628994)

Utilizator SmarandaMaria Pandele Smaranda Data 2 noiembrie 2011 16:01:48
Problema Factorial Scor 100
Compilator cpp Status done
Runda gc_practice Marime 0.56 kb
#include<cstdio>
using namespace std;
long n,p;
void read()
{
	scanf("%ld",&p);
}

long multiplicitate(long x)
{
	long s=0,numitor=5;
	while (x/numitor)
	{
		s=s+x/numitor;
		numitor*=5;
	}
	return s;
}

void rez()
{
	long st,dr,m,g,ok=-1;
	st=1;
	dr=2000000000;
	while (st<=dr)
	{
		m=st+(dr-st)/2;
		g=multiplicitate(m);
		if (g==p)
		{
			ok=m;
		}
		if (g<p)
			st=m+1;
		else
			dr=m-1;
	}
	printf("%ld\n",ok);
}

int main()
{
	
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	
	read();
	rez();
	return 0;
}