Cod sursa(job #2624795)

Utilizator RomanacheRoman Alexandru-George Romanache Data 5 iunie 2020 13:18:08
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>

using namespace std;

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

int p,st,dr,mij,nrz;

int putere5(int x)

{
    int z=0,y;

    y=5;
    while(x>=y)
    {
        z=z+x/y;
        y=y*5;
    }
    return z;
}

int main()
{
    fin>>p;
    if (p==0)
    {
        fout<<1;
        return 0;
    }
    st=5;
    dr=2000000000;
    while(st<=dr)
    {
        mij=(st+dr)/2;
        nrz=putere5(mij);
        if(nrz==p)
        {
            fout<<mij-mij%5;
            return 0;
        }
        else if(nrz<p)
            st=mij+1;
        else
            dr=mij-1;
    }
    fout<<-1;

 return 0;
}