Cod sursa(job #2237618)

Utilizator tangerine515Alex Anton tangerine515 Data 2 septembrie 2018 14:01:46
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <iostream>
#include <fstream>
#include <limits>
#include <vector>

std::fstream fi ("fact.in", std::ios::in);
std::fstream fo ("fact.out", std::ios::out);

int32_t numara_zerouri (int32_t n) {
    int32_t c = 0;
    for (int32_t d = 5; n / d > 0; d = (d << 2) + d) c += n / d;
    return c;
}

int main (void) {
    int32_t p; 
    fi >> p;
    int32_t rez = [&] () -> int32_t {
        int32_t l = 1, h = std::numeric_limits<int32_t>::max(), m = 0;
        while (l <= h) {
            m = (l + h) >> 1;
            (numara_zerouri (m) < p) ? l = m + 1 : h = m - 1; }
        std::vector<int32_t> rez;
        while (numara_zerouri (l) == p) {
            rez.push_back (l); l++;
        }
        return ((!rez.empty ()) ? rez.front () : (-1));
    } ();
    fo << rez;
    return 0;
}