Cod sursa(job #2370853)

Utilizator emadinuDinu Ema emadinu Data 6 martie 2019 14:04:47
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>

using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
long long k,st,dr,mij,ok,prod,cmij,s,cif;
int main()
{

    in>>cif;

    if (cif==0)

        out << 1;

    else {

        st=5;

        dr=400000015;

        while (st<=dr) {

        mij=(st+dr)/2;

        prod=5;

        cmij=mij;

        s=0;

        while (cmij/prod!=0) {

            s+=cmij/prod;

            prod*=5;

        }

        if (s==cif) {

            ok=1;

            break;

        }

        else if (s<cif)

             st=mij+1;

        else

            dr=mij-1;

        }





   if (ok==1)

        out<<mij-mij%5;

    else

        out<< -1;

    }

    return 0;

}