Cod sursa(job #582849)

Utilizator stef93Stefan Gilca stef93 Data 16 aprilie 2011 10:12:45
Problema Factorial Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <cstdio>
using namespace std;

int p;

int nrde0(int x)
{
    int n=x,ok=0;
    while(n/5!=0)
        {
            n/=5;
            ok+=n;
        }
        return ok;
}

int main()
{
    int i,n,ok;
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);
    scanf("%d",&p);
    if(p==0)
    {
        printf("1");
        return 0;
    }
    int step;
    for(step=1;step<100000000;step<<=1);
    for(i=100000000;step;step>>=1)
     if(i-step>0&&nrde0(i-step)>=p)i-=step;
    printf("%d",i);
    fclose(stdout);
    return 0;
}