Cod sursa(job #331411)

Utilizator pykhNeagoe Alexandru pykh Data 13 iulie 2009 21:43:30
Problema Factorial Scor 55
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include<stdio.h>
long lo, hi, mid, P, k, kk;
long desc(long nr)
	{
long i=5,s=0;
	while(nr/i){
		s+=nr/i;
		i*=5;
	}
	return s;
	}

long BS()
	{
		for(lo=1,hi=100000000;lo<=hi;)
		{
		mid=lo+(hi-lo)/2;
		k=desc(mid);
		if(k==P)return mid;
		else if(k<P)lo=mid+1;
		else hi=mid-1;
		}
		return -1;
}

int main()
	{
		freopen("fact.in","r",stdin);
		freopen("fact.out","w",stdout);
		scanf("%ld", &P);
		kk=BS();
		while(kk%5 && kk>0)
			kk--;
		printf("%ld",kk);
		return 0;
}