Cod sursa(job #2437155)

Utilizator robertrRotaru Stefan Robert robertr Data 8 iulie 2019 17:19:44
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <fstream>
#define xmax (1<<30)
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int p;
int descomp(int x)
{
    int s=0;
    while(x>25)
    {
        int p1=5,nr=0;
        while(p1*5<x)
            p1*=5,nr++;
        s+=p1/5+nr;
        x-=p1;
    }
    if(x==25)
        s+=6;
    else s+=x/5;
    return s;
}
int caut_bin(int st,int dr)
{
    int mij=(st+dr)>>1;
    while(st<=dr)
    {
        if(descomp(mij)<p)
            st=mij+1;
        else if(descomp(mij)>p) dr=mij-1;
        else return mij;
        mij=(st+dr)>>1;
    }
    return -1;
}
void read()
{
    f>>p;
    g<<caut_bin(0,xmax);
}
int main(void)
{
    read();
}