Cod sursa(job #95624)

Utilizator radamiRadu Patulescu radami Data 29 octombrie 2007 18:27:44
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <stdio.h>
#include <math.h>

long p,a = 1,b = 1000000000,gasit;
long auxi ;
long zerouri (int x)
{
	long put = 0;
	auxi = x;
		while (auxi > 0)
		{
			put += auxi / 5;
			auxi /= 5;
		}
	
	return put;
	
}

int main ()
 {
	long aux;
	freopen("fact.in","r",stdin);
	freopen("fact.out","w",stdout);
	scanf("%ld",&p);
	while (a != b && !gasit)
	{
		aux = zerouri((a+b)/2);
		if (aux == p)
			gasit = 1;
		else
			if (aux < p)
				a = (a+b)/2 + 1;
			else
				b = (a+b)/2;
	}
	
	long y;
	if (gasit)
		{
			y = (a+b)/2;
			while (y%5)
				--y; 
			if (!y)
				y = 1;
			printf("%ld",y);
		}
	else
		printf("-1");
	
	
	return 0;
 }