Cod sursa(job #597962)

Utilizator mavroMavrodin Bogdan-Florentin mavro Data 24 iunie 2011 02:17:38
Problema Factorial Scor 45
Compilator c Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <stdio.h>

// nr natural minim pt care N! are P zerouri;

int main()
{
    freopen("fact.in", "r", stdin);
    freopen("fact.out", "w", stdout);

    long int p, n = 0, n2, p2 = 0;

    scanf("%ld", &p);
    if(p == 0)
    {
        printf("1");
        return 0;
    }
    
    while(p > p2)
    {
        n = n + 5;
        n2 = n;
        while(n2 % 10 == 0 && n2 != 0)
        {
            n2 = n2 / 10;
            p2++;
        }
        while(n2 % 5 == 0 && n2 != 0)
        {
            n2 = n2 / 5;
            p2++;
        }
        if(p2 == p)
        {
            printf("%ld", n);        
            return 0;
        }
    }
    printf("-1");
    return 0;
}