Cod sursa(job #441342)

Utilizator siminescuPaval Cristi Onisim siminescu Data 12 aprilie 2010 21:22:22
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include<stdio.h>
long long n,p,st=1,dr,bla,t,nr,v[]={5,30,155,780,3805,19530,97655,488280,2441405,12207030,61035155,305175780},i;
int main()
{
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	scanf("%lld",&p);
	for(i=0;i<12;i++)
		if(p==v[i]) bla=1;
	if(bla==1)printf("-1");
	else
	{
	dr=5*p;
	while(st<dr)
	{
		nr=0;
		t=(st+dr)/2;
		bla=5;
		while(bla<=t)
		{
			nr=nr+t/bla;
			bla=bla*5;
		}
		if(nr>=p)
			dr=t;
		else
			st=t+1;
	}
	printf("%lld",st);
	}
	






}