Cod sursa(job #1965877)

Utilizator YouDontNeedMyNameJurcut Paul YouDontNeedMyName Data 14 aprilie 2017 18:07:55
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int exponent_5(long long a)
{
    int e=0;
    while(a%5==0)
    {
        a/=5;
        e++;
    }
    return e;
}
int main()
{
    int p;
    long long nr;
    in >> p;
    if(p==0)
    {
        out << 1;
        return 0;
    }
    else
        nr=0;
    while(p>0)
    {
        nr+=5;
        p-=exponent_5(nr);
    }
    if(p<0)
    {
        out << "-1";
        return 0;
    }
    else
    {
        out << nr;
        return 0;
    }
}