Cod sursa(job #2790838)

Utilizator AnSeDraAndrei Sebastian Dragulescu AnSeDra Data 29 octombrie 2021 17:18:53
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>

using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
long long x,l=1,r=500000000,i,v[10005],mid,sol,d;
int pow5(int h)
{
    int cnt=0;
    d=5;
    while(h>=d)
    {
        cnt=cnt+h/d;
        d=d*5;
    }
    return cnt;
}
int main()
{
    fin>>x;
    if(x==0)
    {
        fout<<1;
    }
    else if(x==1)
    {
        fout<<5;
    }
    else
    {
        while(l<=r)
        {
            mid=(l+r)/2;
            if(pow5(mid)<x)
            {
                l=mid+1;
            }
            else
            {
                sol=mid;
                r=mid-1;
            }
        }
        fout<<sol;
    }
    return 0;
}