Cod sursa(job #2269857)

Utilizator niculaestefan22Stefan Niculae niculaestefan22 Data 26 octombrie 2018 17:39:22
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

int p;

int nrz(int x)
{
    int s=0;
    while(x!=0)
    {
        s=s+x/5;
        x=x/5;
    }
    return s;
}

int main()
{
    fin>>p;
    int st,dr,mij,ans=-1,s;
    st=1;
    dr=2000000000;
    while(st<=dr)
    {
        mij=(st+dr)/2;
        s=nrz(mij);
        if(s==p)
        {
            ans=mij;
            dr=mij-1;
        }
        else if(s<p)
        {
            st=mij+1;
        }
        else dr=mij-1;
    }
    fout<<ans<<"\n";
    fout.close();

    return 0;


}