Cod sursa(job #667128)

Utilizator alexxx92Toader Alexandru alexxx92 Data 22 ianuarie 2012 17:24:52
Problema Factorial Scor 30
Compilator c Status done
Runda Arhiva de probleme Marime 0.71 kb
#include<stdio.h>

int div(int n, int i)
{
    int s=0;
    while(n%i==0)
    {
        n/=i;
        ++s;
    }
    return s;
}


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

    long s=0,i=5,p;

    scanf("%d", &p);

    switch(p)
    {
        case 1: printf("%d", 5); return 0;
        case 2: printf("%d", 10);return 0;
        case 3: printf("%d", 15);return 0;
        case 4: printf("%d", 20);return 0;
        case 5: printf("%d", -1);return 0;
    }

    while(s<p)
        {
            s=s+div(i,5);
            i=i+5;

        }
    i-=5;
    if(s==p)
    printf("%d", i);
    else
        printf("%d", -1);
    return 0;

}