Cod sursa(job #179063)

Utilizator ghiutaalexGhiuta Alex ghiutaalex Data 15 aprilie 2008 15:53:33
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
#include<stdio.h>
#include<values.h>
int main()
{long long unsigned p,a,b,c,r,d,ok=0,i;
 FILE*f=fopen("fact.in","r");
 FILE*g=fopen("fact.out","w");
 fscanf(f,"%lld",&p);
 a=1;b=MAXLONG;
 if(p==5) fprintf(g,"-1");
 else{
 while(a<=b&&!ok)
       {c=(a+b)/2;
	d=c;
	r=0;
	while(d) {d/=5;
		  r+=d;}
	if(r==p) ok=1;
	else if(r>p) b=c-1;
	     else a=c+1;}
 if(!ok) fprintf(g,"-1");
 else {while(c%5) c--;
       fprintf(g,"%lld",c);}}
 fcloseall();
 return 0;
}