Cod sursa(job #11920)

Utilizator Agent_SmithSilaghi Raul Agent_Smith Data 2 februarie 2007 12:29:15
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include<stdio.h>
#include<math.h>
long int n,c,b,a,k,p;
long int h(long int x)
{
 long int y=0;
 while(x)
 {
   y=y+x/5;
   x=x/5;
 }
 return y;
}
long int divide(long int a,long int b)
{
 long int putere;
 while(a<b)
 {
  c=(a+b)/2;
  putere=h(c);
  if(putere<p) return divide(c,b);
  else if(putere>p) return divide(a,c);
  else return c;

 }
}
void main()
{

 FILE *in=fopen("fact.in","rt");
 fscanf(in,"%ld",&p);
 fclose(in);
 FILE *out=fopen("fact.out","wt");
 a=0;b=100000000;
 k=divide(a,b);
 while(k%5) --k;
 if(h(k)==p) printf("\n%ld",k);
 else printf("-1");
 fclose(out);
}