Cod sursa(job #1021955)

Utilizator teodor98Teodor Sz teodor98 Data 4 noiembrie 2013 15:12:52
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <stdlib.h>
#include <stdio.h>

int main()
{
    freopen("fact.in", "rt", stdin);
    freopen("fact.out", "wt", stdout);
    int k,p,n,putere;
    scanf("%d", &p);

    n = 4*p,k=0;putere=5;
    while(n/putere)
     k += n/putere, putere *= 5;
    n = 5*(n/5+1);
    do {
        putere= 5, k = 0;
        while(n/putere) k += n/putere, putere *= 5;
        n += 5;
    } while(k < p);
    n -= 5;
    if(p == 0) printf("%d", 1);
    else {
        if(k == p)     printf("%d",n);

        else     printf("%d",-1);
;
    }


    return 0;
}