Cod sursa(job #1730066)

Utilizator Dragne.Andrei11Dragne Andrei Dragne.Andrei11 Data 16 iulie 2016 12:19:52
Problema Factorial Scor 45
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <cstdio>

using namespace std;

inline short fct(int n)
{
    int x=0;
    while(n%5==0)
    {
        n/=5;
        x++;
    }
    return x;
}
int main()
{
    freopen("fact.in", "r", stdin);
    freopen("fact.out", "w", stdout);
    int p;

    scanf("%d", &p);
    if(p==0)
    {
        printf("1\n");
        return 0;
    }
    int n=5;
    int p1=0;
    while(n)
    {
        p1+=fct(n);
        if(p1==p)
        {
            printf("%d\n", n);
            return 0;
        }
        if(p1>p)
        {
            printf("-1");
            return 0;
        }
        n+=5;
    }

    return 0;
}