Cod sursa(job #2702592)

Utilizator mihnea18Ciubotariu Mihnea mihnea18 Data 4 februarie 2021 21:01:38
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 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;
        }
    }
}