Cod sursa(job #540016)

Utilizator EugenStoicaEugen Stoica EugenStoica Data 23 februarie 2011 17:14:20
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include<fstream>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

long long p;

int x[1000];
long long act=4;

long long nr_zero(long long x)
{
    long long nr = 0;
    long long ulterm = 5;
    while(ulterm<=x)
    {
        nr += x/ulterm;
        ulterm*=5;
    }
    return nr;
}

void gen()
{
    for(int i=0;;i+=5)
    {
        long long nrz = nr_zero(i);
        if(nrz > p) return;
        x[nr_zero(i)] = i;
    }
}

int main()
{
    fin>>p;
    gen();
    if(!x[p])fout<<"-1";
    else fout<<x[p];
    return 0;
}