Cod sursa(job #354737)

Utilizator Adela_BaciuAdela Baciu Adela_Baciu Data 9 octombrie 2009 12:07:39
Problema Factorial Scor 100
Compilator cpp Status done
Runda cautb1 Marime 0.41 kb
#include<cstdio>
int zero(int n)
{
	int nrzero=0;
	while(n)
	{
		nrzero+=(n/=5);
	}
	return nrzero;
}
int cb(int p)
{
	int i,pas=(1<<30);
	for(i=0;pas;pas>>=1)
		if(zero(i+pas)<=p-1)
			i+=pas;
	if(zero(i+1) != p)
		return -1;
	return i+1;
}

int main()
{
	int nr,p;
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	scanf("%d",&p);
	nr=cb(p);
	printf("%d",nr);
	return 0;
}