Cod sursa(job #327155)

Utilizator ZethpixZethpix Zethpix Data 27 iunie 2009 13:43:36
Problema Factorial Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <fstream>
FILE *f,*g;
long n;
long numar;
long ok(long n){
 long s=0;
 long p=5;
 while (p<=n){
  s+=n/p;
  p*=5;
 }
 return s;
}
void cbin(long x,long y){
 long m=0;
 m=(x+y)/2;
 long p=ok(m);
 if (p<n) cbin(m+1,y);
  else
 if (p>n) cbin(x,m-1);
  else{
   while (ok(m)==n) m--;
   numar=m+1;
  }
}
int main(){
 f=fopen("fact.in","r");
 g=fopen("fact.out","w");
 fscanf(f,"%ld",&n);
 cbin(0,1000000000);
 fprintf(g,"%ld",numar);
 fclose(f);
 fclose(g);
 return 0;
}