Cod sursa(job #640968)

Utilizator dorelStoica Razvan-Andrei dorel Data 26 noiembrie 2011 21:27:58
Problema Factorial Scor 100
Compilator c Status done
Runda Arhiva de probleme Marime 0.4 kb
#include <stdio.h>
int cont (int t)
{
	int r=0;
	while (t >= 5)
	{
		r+=t/5;
		t/=5;
	}
	return r;
}
int ans (int Z)
{
	int i,j=1<<29;
	for (i=0 ; j!=0 ; j=j>>1)
	{
		if (cont(i+j) < Z)
			i+=j;
	}
	return i+1;	
}
int main ()
{
	int P,N;
	freopen ("fact.in","r",stdin);
	freopen ("fact.out","w",stdout);
	scanf ("%d",&P);
	N=ans(P);
	if (cont (N) == P)
		printf ("%d",N);
	else
		printf ("-1");
	return 0;
}