Cod sursa(job #2702133)

Utilizator vlad2009Vlad Tutunaru vlad2009 Data 2 februarie 2021 22:47:54
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>

using namespace std;

int main()
{
    unsigned long long p, x, nr, k;
    ifstream fin( "fact.in" );
    ofstream fout( "fact.out" );
    fin >> p;
    if (p == 0)
    {
        fout << 1;
    }
    else
    {
        x = 5 * ( p - p / 5 );
        while (nr < p)
        {
            nr = 0;
            k = 5;
            while (k <= x)
            {
                nr += x / k;
                k *= 5;
            }
            if (nr < p)
            {
                x += 5;
            }
        }
        if (nr == p)
        {
            fout << x;
        }
        else
        {
            fout << -1;
        }
    }
}