Cod sursa(job #1694486)

Utilizator fotadavidFota David fotadavid Data 25 aprilie 2016 15:18:42
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <cstdio>

using namespace std;
int Zero( int n )
{
    long long p5 = 5;
    int s = 0;
    while( p5 <= n )
        s += n / p5, p5 *= 5;
    return s;
}
int Caut_Bin( int p )
{
    int n = 0, pas = 1 << 29;
    while( pas > 0 )
    {
        if( Zero(n + pas) < p )
            n += pas;
        pas /= 2;
    }
    if(Zero(n + 1) == p)
        return n + 1;
    return -1;
}
int main()
{
    freopen("fact.in", "r", stdin);
    freopen("fact.out", "w",  stdout);
    int p;
    scanf("%d", &p);
    printf("%d", Caut_Bin(p));
    return 0;
}