Cod sursa(job #623028)

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

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

int main()
{
    unsigned int n,p,c;
    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
        c = count(n);
        while (p>c)
        {
            n+=5;
            c = count(n);
        }
        if (c==p)
            printf("%d\n",n);
        else
            printf("-1\n");
    }
    else
        printf("1\n");
    return 0;
}