Cod sursa(job #2372078)

Utilizator etienAndrone Stefan etien Data 6 martie 2019 21:16:55
Problema Factorial Scor 85
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include<fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p,st,dr,mi,poz;
int cifrede0(int put)
{
    int po=1,exp2=0,exp5=0;
    while(po*2<=put)
    {
        po*=2;
        exp2+=put/po;
    }
    po=1;
    while(po*5<=put)
    {
        po*=5;
        exp5+=put/po;
    }
    return min(exp2,exp5);
}
int main()
{
    fin>>p;
    st=1;
    dr=10*p;
    while(st<=dr)
    {
        mi=(st+dr)/2;
        if(cifrede0(mi)>p)
            dr=mi-1;
        else if(cifrede0(mi)<p)
            st=mi+1;
        else
        {poz=mi;
        dr=mi-1;}
    }
    fout<<poz;
}