Cod sursa(job #1312809)

Utilizator Tzappy90Mihalache Constantin Tzappy90 Data 9 ianuarie 2015 22:45:32
Problema Factorial Scor 35
Compilator c Status done
Runda Arhiva de probleme Marime 0.44 kb
#include <stdio.h>
long p,l=1,r = 400000015/5,m,test;
long int zero(int n)
{
	long int p=0;
	while(n>=5)
	{
		p+=n/5;
		n/=5;
	}
	return p;
}
int main()
{
	FILE *in = fopen("fact.in","r");
	FILE *out = fopen("fact.out","w");
	fscanf(in,"%ld",&p);
	while(l<r)
	{
		m = (l+r)/2;
		test = zero(5*m);
		if(test==p)
			break;
		else
		{
			if(test<p)
				l = m+1;
			else
				r = m-1;
		}
	}
	fprintf(out,"%ld\n",5*m);
	fclose(in);fclose(out);
	return 0;
}