Cod sursa(job #2792997)

Utilizator vzzev edmond vzze Data 2 noiembrie 2021 17:41:49
Problema Factorial Scor 65
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>

bool check(size_t n, size_t p) {

    size_t x = 0;

    size_t i = 5;

    while(n >= i) {
        x += n / i;
        i *= 5;
    }

    return x >= p;
}

size_t find(size_t n) {
    size_t low = 0;
    size_t high = 5 * n;

    while(low < high) {
        size_t mid = (low + high) / 2;

        if(check(mid, n))
            high = mid - 1;
        else
            low = mid + 1;
    }

    return low;
}

int main() {
    std::ifstream f("fact.in");
    std::ofstream o("fact.out");

    size_t n; f >> n; o << find(n);

    f.close();
    o.close();
}