Cod sursa(job #623005)

Utilizator cristianalex81Cristian Alexandru cristianalex81 Data 18 octombrie 2011 21:13:13
Problema Factorial Scor 90
Compilator c Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <stdio.h>
#include <stdlib.h>

unsigned int n,p;

unsigned int count (unsigned int n)
{
    unsigned int c=0;
    while (n!=0)
    {
        c+=n/5;
        n/=5;
    }
    return c;
}

int main()
{
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);
    scanf("%d",&p);
    if (p!=0)
    {
        n = 4*p;
        n += (5-n%5); // round up to the nearest multiple of 5
        while (p != count(n))
        {
            n+=5;
        }
        printf("%d\n",n);
    }
    else
        printf("1\n");
    return 0;
}