Cod sursa(job #1089890)

Utilizator vladradu2014Radu Vlad Alexandru vladradu2014 Data 22 ianuarie 2014 00:33:28
Problema Factorial Scor 10
Compilator c Status done
Runda Arhiva de probleme Marime 0.92 kb
#include<stdio.h>
#include<stdlib.h>

int log5(int a){
 int count=0;
 while(a/5!=0)
 {
     count++;
     a=a/5;
 }
 return count;
}

int main(int argc,char** argv){

  FILE *fp;
  int p;
  int rez;
  int lf;
  int f;
  int count;

  if((fp=fopen("fact.in","r"))==NULL){
     perror("fact.in :");
     return 1;
  }
  
  fscanf(fp,"%d",&p);
  fclose(fp);
  
  
  if((fp=fopen("fact.out","w"))==NULL){
     perror("fact.out :");
     return 1;
  }
  
  if(p==0)
    fprintf(fp,"%d",1);
  else{
     f=0;
     count=0;
     
     while(1){
      lf=log5(f);
      if(count>p)
      {
          rez=-1;
          break;
          
      }
      if(count==p)
      {
            rez=f;
            break;
      }
      f+=5;
      if(log5(f)!=lf)
         count+=log5(f);
      else
         count+=1;
    }
    fprintf(fp,"%d",rez);
	
  }
  
  fclose(fp);
  return 0;

}