Cod sursa(job #2357583)

Utilizator BAlexandruBorgovan Alexandru BAlexandru Data 27 februarie 2019 16:09:57
Problema Factorial Scor 55
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>

using namespace std;

ifstream f("fact.in");
ofstream g("fact.out");

long long n,i,j,st,dr,m;
int gasit;

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

int main()
{
    f>>n;
    st=1;
    dr=100000000;
    gasit=0;
    while (st<=dr && gasit==0)
    {
        m=(st+dr)/2;
        if (nr_zero(m)<n)
            st=m+1;
        else
            if (nr_zero(m)>n)
                dr=m-1;
            else
                gasit=1;
    }
    if (gasit==1)
    {
        while (nr_zero(m)==n)
            m--;
        g<<m+1;
    }
    else
        g<<-1;
    return 0;
}