Cod sursa(job #228802)

Utilizator patricia_iIosifescu Patricia patricia_i Data 8 decembrie 2008 01:16:33
Problema Factorial Scor 55
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include<stdio.h>
long long unsigned p,st=1,c,dr=100000000,m,n,a,i,b;
int gasit=0;
long long unsigned nrzr(long long unsigned c)
{
p=0;
 while(c)
	   {
		     p+=c/5;
		     c/=5;
	   }
 return p;
}
int main()
{
FILE *f=fopen("fact.in","r"), *g=fopen("fact.out","w");
fscanf(f,"%llu",&n);
if (n==0)
   fprintf(g,"%d",1);
   else
    {while (st<dr&&!gasit)
	  {m=(st+dr)/2;
	  a=nrzr(m);
	  if (n==a)
	     gasit=1;
	     else
		if (a<n)
		  st=m+1;
		  else dr=m-1;
	  }
if (gasit)
{  b=m;
for (i=m;i>=m-5;--i)
	{a=nrzr(i);
	if (a==n)
	     b=i;
	}
}
if (!gasit)
   fprintf(g,"%d",-1);
		     else fprintf(g,"%llu",b);
}
return 0;
}