Cod sursa(job #535819)

Utilizator wabbitLarion Octavian wabbit Data 17 februarie 2011 20:04:30
Problema Factorial Scor 95
Compilator c Status done
Runda Arhiva de probleme Marime 0.74 kb
#include<stdio.h>
#include<math.h>

long int p;

long int cauta(long int a,long int b)
{
     long int c=(a+b)/2,s=0;
     int y=5;
     
     while(y<=c)
      {
       s+=c/y;     
       y*=5;                            
      }
      
     if(s==p) {if(c%5) return c-c%5; else return c;}
     else {if(a==b) return -1;
           if(s<p) return cauta(c+1,b);
           if(s>p) return cauta(a,c-1);  
            
            }         
     
} 

int main()
{
    long int x;
   
   FILE *f=fopen("fact.in","rt");  
   fscanf(f,"%ld",&p);
 
   FILE *h=fopen("fact.out","wt");
   if(p==0) fprintf(h,"1");
   else if(p==1) fprintf(h,"5");
        else {x=cauta(0,5*p); fprintf(h,"%ld",x);}
   
  
   return 0; 
    }