Cod sursa(job #2622406)

Utilizator denisa.iordacheIordache Denisa-Elena denisa.iordache Data 1 iunie 2020 11:27:12
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <iostream>
#include <fstream>
using namespace std;
long p;
long nr_0(long x)
{
    long nr=0,divizor=5;
    while(x/divizor!=0)
    {
            nr+=x/divizor;
            divizor=5*divizor;
    }
    return nr;

}

long CB(long st,long dr)
{
    long mij;
    while(st<dr)
    {
        mij=st+(dr-st)/2;
        if(nr_0(mij)==p)
        {
            while(nr_0(mij-1)==p)
                mij--;
            return mij;
        }
        else
            if(nr_0(mij)<p)
                st=mij+1;
                else
                    dr=mij-1;
    }
    return -1;
}

int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
    f>>p;
    if(p==0)g<<1;
    else
        g<<CB(1,10*p);
   return 0;
}