Cod sursa(job #2437146)

Utilizator robertrRotaru Stefan Robert robertr Data 8 iulie 2019 17:10:20
Problema Factorial Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int p;
inline bool valid(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==p;
}
int caut_bin(int st,int dr)
{
    int mij=(st+dr)>>1;
    while(st<=dr)
    {
        if(valid(mij)==true)
            dr=mij-1;
        else st=mij+1;
        mij=(st+dr)>>1;
    }
    return st;
}
void read()
{
    f>>p;
    g<<caut_bin(1,p*5);
}
int main(void)
{
    read();
}