Cod sursa(job #16653)

Utilizator robbyRobertino robert robby Data 13 februarie 2007 20:33:42
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <stdio.h>
FILE *f,*g;
long long p,s,i,j,r,k;
int main()
{
   FILE *f=fopen("fact.in","rt");
   FILE *g=fopen("fact.out","wt");
   fscanf(f,"%lld",&p);
   j=p-p/5-1;
   s=0;
   k=0;
   while (s!=p&&j<p&&k<100000)
	 {
	   k++;
	   j++;
	   s=0;
	   i=j;
	   while (i>0)
		 {
		   s+=i;
		   i/=5;
		 }
	 }
   if (p==0)
	 fprintf(g,"1\n");
	else
	 if (s==p)
	   fprintf(g,"%lld\n",j*5);
	  else
	   fprintf(g,"-1\n");
   fclose(f);
   fclose(g);
   return 0;
}