Cod sursa(job #2330398)

Utilizator nicolas45nicolas deletanche nicolas45 Data 28 ianuarie 2019 12:29:26
Problema Factorial Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
unsigned long long  zerof(unsigned long long n)
{
    unsigned long long nrz=0,p5=5;
    while(p5<=n)
    {
        nrz=nrz+n/p5;
        p5*=5;
    }
    return nrz;
}

int main()
{
    unsigned long long mijl,max,min=0,gasit=0,n,nr;
    //cout<<max;
    fin>>n;
    max=5*n;
    while(min<=max && !gasit)
    {
        mijl=(min+max)/2;
        nr=zerof(mijl);
        if(nr==n)
            gasit=1;
        if(nr>n)
            max=mijl-1;
        else
            min=mijl+1;
    }

    if(gasit==0)
        fout<<"-1";
    else
        fout<<mijl/5*5;

    return 0;
}