Cod sursa(job #2289695)

Utilizator CristyXtremeSimion Cristian CristyXtreme Data 25 noiembrie 2018 00:36:30
Problema Factorial Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <stdio.h>

using namespace std;

int nr_zero(int x) {
    int nr = 0, div = 5;
    while (div <= x) {
        nr += x / div;
        div *= 5;
    }
    return nr;
}

int caut(int p) {
    int pos, i;
    for (pos = 1; pos < 5 * p; pos <<= 1);
    for (i = 5 * p, pos >>= 1; pos; pos >>= 1)
        if (i - pos >= 0 && nr_zero(i - pos) >= p)
            i -= pos;
    if (nr_zero(i) == p)
        return i;
    return -1;
}

int main()
{
    freopen("fact.in", "r", stdin);
    freopen("fact.out", "w", stdout);
    int p;
    scanf("%i", &p);
    printf("%d", caut(p));
    return 0;
}