Cod sursa(job #1812939)

Utilizator andreigasparoviciAndrei Gasparovici andreigasparovici Data 22 noiembrie 2016 16:11:26
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <cstdio>

using namespace std;

int zero(int x, int p)
{
    int s = 0, c = 5;
    while(c <= x)
    {
        s += x/c;
        c = c * 5;
    }
    return s;
}

int p,st=1,dr=2000000000;

int main()
{
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);

    scanf("%d",&p);

    while(st <= dr)
    {
        int mij=(st+dr)/2;
        if(zero(mij, p) < p)
            st = mij+1;
        else
            dr = mij-1;
    }
    if(zero(st, p) == p)
        printf("%d",st);
    else printf("-1");
    return 0;
}