Cod sursa(job #1506566)

Utilizator SilviuIIon Silviu SilviuI Data 20 octombrie 2015 19:54:25
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <stdio.h>
using namespace std;
long long int n,st,dr,m,sol,l;
long long int nrzero(long long int x)
{
    long long int b=0;
    while (x>0) {
        b=b+x/5; x=x/5;
    }
    return b;
}
int main() {
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%lld",&n);
st=1; dr=10000000000; sol=-1;
while (st<=dr) {
    m=(st+dr)/2; l=nrzero(m);
    if (l==n) { sol=m; dr=m-1;
    } else
    if (l>n) dr=m-1; else st=m+1;
}
printf("%lld",sol);
return 0;
}