Cod sursa(job #758152)

Utilizator PopdanDanielPopdan Daniel PopdanDaniel Data 14 iunie 2012 17:06:21
Problema Factorial Scor 95
Compilator c Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <stdio.h>
#include <stdlib.h>
int s=0;
void putere(int a)
    {
        int k=5;
        s=0;
        while(a >= k)
        {
            s=s+(a/k);
            k=k*5;
        }
    }
int cautare (int p)
    {
        int i,j;
        j=4*p;
        while((j%5)!=0)
        j++;
        for (i=j; i<=5*p; 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);
    return 0;
}