Cod sursa(job #3201585)

Utilizator Theo20067Cismaru Theodor-Alexe Theo20067 Data 9 februarie 2024 09:05:01
Problema Factorial Scor 85
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <fstream>
using namespace std;
ifstream fin ("fact.in");
ofstream fout("fact.out");
long long st,dr,p,mid;
long long zero(long long x)
{
    long long l=5;
    long long c=x;
    long long nr=0;
    while(c>l)
    {
        nr+=c/l;
        l*=5;
    }
    return nr;
}
int main()
{
    fin>>p;
    st=1;
    dr=1e17;
    while(st<=dr)
    {
        mid=(st+dr)/2;
        if(zero(mid)>=p)
            dr=mid-1;
        else
            st=mid+1;
    }
    fout<<st;
    return 0;
}