Cod sursa(job #574495)

Utilizator PetcuIoanPetcu Ioan Vlad PetcuIoan Data 7 aprilie 2011 11:19:40
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#include<stdio.h>
int leg(int med)
{
	int z=0;
	while(med/5)
	{
		z+=med/5;
		med/=5;
	}
	return z;
}
int bs(int p)
{
	int st=1,dr=2e9,med,last=-1,x;
	while(st<=dr)
	{
		med=st+((dr-st)>>1);
		x=leg(med);
		if(x>p)
			dr=med-1;
		if(x==p)
		{
			last=med;
			dr=med-1;
		}
		if(x<p)
			st=med+1;
	}
	return last;
}
int main()
{
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	int p,x;
	scanf("%d",&p);
	x=bs(p);
	printf("%d",x);
	return 0;
}