Cod sursa(job #758150)

Utilizator bratualexBratu Alexandru bratualex Data 14 iunie 2012 16:55:18
Problema Factorial Scor 95
Compilator c Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <stdio.h>
#include <stdlib.h>
int s=0;
int putere(int a)
    {
        int k=5;
        s=0;
        while(a >= k)
        {
            s=s+(a/k);
            k=k*5;
        }
    }
int cautare (int p)
    {
        int i,k;
        k=4*p;
        while ( k%5 )
        k--;
        for (i=k; i<=5*p; i=i+5)
            {

                putere(i);
                if(s==p)
                return i;
            }
        return -1;
    }
int main()
{
   FILE *pf,*fp;
    int p,n;
    pf=fopen("fact.in", "r");
    fscanf(pf,"%d", &p);
    fclose(pf);
    if(p==0)
    n=1;
    else
    n=cautare(p);
    fp=fopen("fact.out", "w");
    fprintf(fp,"%d", n);
    fclose(fp);
}