Cod sursa(job #29360)

Utilizator undogSavu Victor Gabriel undog Data 9 martie 2007 09:33:09
Problema Factorial Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include<stdio.h>
long p,found;


int check(long m){
 long i;
 for(i=0;m>4;i++)
  m-=5;
 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;
   return;
  }
  else
   binsrc(m+1,ls);

}

int main(){

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

scanf("%ld",&p);

binsrc(0,1000000);

printf("%ld",found);

}