Cod sursa(job #2257346)

Utilizator TeddyDinutaDinuta Eduard Stefan TeddyDinuta Data 9 octombrie 2018 23:09:11
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <bits/stdc++.h>

using namespace std;
long long n,l,r,m,p,z,ans;
int main()
{
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);
    scanf("%lld",&n);
    l=1;
    r=1e17;
    while(l<=r)
    {
        z=0;
        p=1;
        m=(l+r)/2;
        while(p*5<=m)
        {
            p*=5;
            z+=m/p;
        }
        if(z>=n)
        {
            r=m-1;
            ans=m;
        }
        else l=m+1;
    }
    printf("%lld",ans);
    return 0;
}