Cod sursa(job #29454)

Utilizator undogSavu Victor Gabriel undog Data 9 martie 2007 14:10:38
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include<stdio.h>
long p,found;


int check(long m){
 long i;



 long aux;
 for(i=0;m>0;i++){
  for(aux=m;aux%5==0;aux/=5)
  i++;
  m--;
 }



 if(i<p)
  return 1;
 else
  if(i==p)
   return 0;
  else
   return -1;
}


void binsrc(long ld,long ls){
 long m=(ld+ls)/2;

  if(ld>ls){
  found=-1;
  return;
 }
 int i=check(m);

 if(i==-1)
  binsrc(ld,m-1);
 else
  if(i==0){
   found=m*5;
   return;
  }
  else
   binsrc(m+1,ls);

}

int main(){

freopen("fact.in","rt",stdin);
freopen("fact.out","w+",stdout);

scanf("%ld",&p);

binsrc(0,200000);

printf("%ld",found);

}