Cod sursa(job #245724)

Utilizator GheorgheMihaiMihai Gheorghe GheorgheMihai Data 18 ianuarie 2009 19:04:16
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include<stdio.h>
long p;


void read()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%ld",&p);
}


long nrzero(long x)
{
return x/5+x/25+x/125+x/625+x/3125+x/15625+x/78125+x/390625+x/1953125+x/9765625+x/48828125+x/244140625;
}


void rez()
{
long st,dr,m,nrdezero;
st=1;
dr=p*5;
while(st<=dr)
	{
	m=(st+dr)>>1;
	nrdezero=nrzero(m);
	if(nrdezero==p)
		{
		if(m%5)
			{
			do
				{
				m--;
				}while(m%5);
			}
		printf("%ld",m);
		return;
		}
	if(nrdezero<p)
		st=m+1;
	else
		dr=m-1;
	}
printf("-1");
}


int main()
{
read();
rez();
return 0;
}