Cod sursa(job #489800)

Utilizator TheBottleNicolae Sapoval TheBottle Data 3 octombrie 2010 16:52:51
Problema Factorial Scor 15
Compilator c Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <stdio.h>

FILE *in,*out;
int k,s,c,p;

int evp(int n)
{
    int i;
    for(i=0;i<k;i++)
    {
               n=n/5;
               s=s+n;    
               }
    return s; 
    }

void chk()
{
    k=k+1;
    }
    
int cmp(int p, int n)
{
     c=0;
     n=0;
     k=0;
     if(p==0)
     {
             return 1;
             }
     do
     {
                 n=n+5;
                 c++;
                 if(c>=4)
                 {
                         c=0;
                         chk();
                         }
                 }
     while(p>evp(n));
     if(p==evp(n))
     {
                  return n;
                  }
     else 
     {
          return -1;
          }            
     }
     
int main()
{
    in=fopen("fact.in","r");
    fscanf(in,"%d",&p);
    fclose(in);
    out=fopen("fact.out","w");
    fprintf(out,"%d",cmp(p,0));
    fclose(out);    
    }