Cod sursa(job #2609307)

Utilizator TeddyDinutaDinuta Eduard Stefan TeddyDinuta Data 2 mai 2020 13:42:03
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda igorj_mentorat1 Marime 0.57 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=100000000000000001;
    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;
            if(z==n) ans=m;
        }
        else l=m+1;
    }
    if(ans==0) printf("%d",-1);
    else printf("%lld",ans);
    return 0;
}