Cod sursa(job #2361534)

Utilizator Xutzu358Ignat Alex Xutzu358 Data 2 martie 2019 16:36:33
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
#define LL long long
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
LL k,st,dr,mij,ok,prod,cmij,s,cif;
int main()
{
    f>>cif;
    if (cif==0)
        g << 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)
        g<<mij-mij%5;
    else
        g << -1;
    }
    return 0;
}