Cod sursa(job #73317)

Utilizator ProtomanAndrei Purice Protoman Data 17 iulie 2007 18:50:33
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <stdio.h>
FILE *f1,*f2;
long x,m,p,c,s,ok1,ok2;

void putere(long x)
{
	p=1;
	s=0;
	while (p*5<=x)
	{
		p=p*5;
		s=s+x/p;
	}
}

void search(long li,long ls)
{
	m=(li+ls)/2;
	putere(m);
	ok1=s;
	putere(m-1);
	ok2=s;
	if (ok1==x && ok2<x) c=m;
	else if (li<ls)
		if (ok2>=x) search(li,m-1);
		else search(m+1,ls);
}

int main()
{
	f1=fopen("fact.in","r");
	f2=fopen("fact.out","w");
	fscanf(f1,"%ld",&x);
	search(1,1000000000);
	if (c==0) c--;
	if (x==0) c=1;
	fprintf(f2,"%ld",c);
	fclose(f1);
	fclose(f2);
	return(0);
}