Cod sursa(job #2402951)

Utilizator BAlexandruBorgovan Alexandru BAlexandru Data 11 aprilie 2019 10:18:59
Problema Factorial Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>

using namespace std;

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

int p,st,dr,mij,gasit,rez;

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

int main()
{
    f>>p;
    st=1,dr=1000000000;
    while (st<=dr && gasit==0)
    {
        mij=(st+dr)/2;
        if (zero(mij)==p)
        {
            rez=mij;
            gasit=1;
        }
        else
            if (zero(mij)<p)
                st=mij+1;
            else
                dr=mij-1;
    }
    if (gasit==1)
    {
        while (zero(rez)==p)
            rez--;
        rez++;
        g<<rez;
    }
    else
        g<<-1;
    return 0;
}