Cod sursa(job #2237585)

Utilizator tangerine515Alex Anton tangerine515 Data 2 septembrie 2018 13:20:50
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.15 kb
#include <iostream>
#include <fstream>
#include <limits>
#include <vector>

#include <cassert>

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

void b_div (int64_t &n, int64_t d) {
    int sgn = ((n < 0) ^ (d < 0)) ? -1 : 1;
    n = std::abs (n); d = std::abs (d);
    int64_t q = 0, t = 0;
    for (int16_t i = 31; i >= 0; --i) {
        if (t + (d << i) <= n) {
            t += (d << i); q |= (1LL << i);
        }
    } n = sgn * q;
}

int64_t numara_zerouri (int64_t n) {
    /*int64_t c = 0; while (n > 0) {
        b_div (n, 5); c += n; }*/
    int64_t c = 0;
    for (int64_t d = 0; n / d > 0; d *= 5)
        c += n / d;
    return c;
}

int64_t caut_bin (int64_t n) {
    int64_t l = 1, h = std::numeric_limits<int64_t>::max(), m = 0;
    
    while (l <= h) {
        m = (l + h) / 2;
        (numara_zerouri (m) < n) ? l = m + 1 : h = m - 1;
    }
    
    std::vector<int64_t> rez;
    while (numara_zerouri (l) == n) {
        rez.push_back (l); l++;
    }
    
    return ((!rez.empty ()) ? rez.front () : (-1));
}

int main (void) {
    int64_t p;
    assert (fi >> p);
    assert (fo << caut_bin (p));
    return 0;
}