Cod sursa(job #401715)

Utilizator stephy_yoyoIonescu Stefania stephy_yoyo Data 23 februarie 2010 08:08:57
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
# include <cstdio> 

int expo (long long a) 
{
	int nr=0;
	while (a>0)
	{
		nr=nr+a/5;
		a=a/5;
	}
	return nr;
}
int main ( )
{
	freopen ("fact.in","r",stdin);
	freopen ("fact.out","w",stdout);
	long long n,p,max,min,t,x;
	scanf ("%lld",&p);
	max=500000000;
	min=0;
	t=0;//inca nu l-am gasit pe n
	while (t==0 && min<=max)
	{
		x=expo((max+min)/2);
		if(p>x)
			min=(max+min)/2+1;
		if (p<x)
			max=(max+min)/2-1;
		if (p==x)
		{
			n=(max+min)/2;
			n=n-n%5;
			t=1;
		}
	}
	if (t==0)
		printf("-1");
	else 
	{
		if (n==0)
			n=1;
		printf ("%lld",n);
	}
	return 0;
}