Cod sursa(job #490437)

Utilizator ioanabIoana Bica ioanab Data 6 octombrie 2010 16:17:44
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include <stdio.h>

int nr(int n)
{
	int nr=0;
	while(n>=5)
	{
		nr=nr+n/5;
		n=n/5;
	}
	return nr;
}

int main()
{
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	int p,st,dr,num,m;
	scanf("%d",&p);
	st=1;
	dr=1<<30;
	while(st<=dr)
	{
		m=(st+dr)/2;
		num=nr(m);
		if(num<p)
			st=m+1;
		else
			dr=m-1;
	}
	if(nr(st)==p)
		printf("%d\n",st);
	else
		printf("-1");
	
	return 0;
}