Cod sursa(job #431690)

Utilizator DanandreighGheorghe Dan Andrei Danandreigh Data 1 aprilie 2010 12:14:59
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <stdio.h>
int p;
int zero(int q)
{int i,s;
i=5;s=0;
while (q/i>0)
{s=s+q/i;
i=i*5;
}
return s;
}
int cautare(int i,int j)
{if (i<=j)
	{int k=(i+j)/2,m;
m=zero(k);
if (m==p) return k;
else if (m>p) return cautare(i,k-1);
	else return cautare(k+1,j);}
	else return -1;
}
int main()
{int t;
	FILE *f=fopen("fact.in","r");
FILE *g=fopen("fact.out","w");
fscanf(f,"%d",&p);
t=cautare(1,500000000);
if (t>0)
while (t%5>0)
	t--;
if (p==0) t=1;

fprintf(g,"%d",t);
fclose(f);
fclose(g);
return 0;
}