Cod sursa(job #1803561)

Utilizator andreinichitaTirziu Nichita andreinichita Data 11 noiembrie 2016 16:33:58
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <cstdio>

using namespace std;
int nr_cif(int n)
{
    int r,s=0;
    r=5;
    while(r<=n)
    {
        s=s+n/r;
        r=r*5;
    }
    return s;
}
int main()
{
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);
    int p,st,dr;
    scanf("%d",&p);
    if(p)
    {
        st=1;
        dr=1<<30;
        while(dr!=0)
        {
            if(nr_cif(st+dr)<p)
                st=st+dr;
            dr=dr/2;
        }
        st++;
        if(nr_cif(st)!=p)
            printf("-1");
        else
            printf("%d",st);
    }
    else
        printf("1");
    return 0;
}