Cod sursa(job #629037)

Utilizator stephy_yoyoIonescu Stefania stephy_yoyo Data 2 noiembrie 2011 16:33:55
Problema Factorial Scor 95
Compilator cpp Status done
Runda gc_practice Marime 0.71 kb
# include<stdio.h>

long long zero (long long n)
{
    long long s=0;
    for(;n;n/=5)
        s+=n/5;
    return s;
}

int main ()
{
    freopen ("fact.in","r",stdin);
    freopen ("fact.out","w",stdout);
    long long sf=1000000000,in=1,curent,p,t=1,indice;
    scanf ("%lld",&p);
    for (in=1;in<=sf;)
    {
        indice=in+(sf-in)/2;
        curent=zero(indice);
        if (curent==p)
        {
            printf("%lld",indice-indice%5);
            t=0;
            break ;
        }
        if (p<curent)
            sf=indice-1;
        else
            in=indice+1;
        //printf ("%lld %lld %lld\n",in,sf,curent);
    }
    if (t)
        printf("-1");
    return 0;
}