Cod sursa(job #2482525)

Utilizator mirunazMiruna Zavelca mirunaz Data 28 octombrie 2019 14:11:14
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
using namespace std;
ifstream in ("fact.in");
ofstream out("fact.out");

int count_zero(int x) {
    int p = 5, ct = 0;
    while (p <= x) {
        ct += x / p;
        p *= 5;
    }
    return ct;
}

void fin(int x, int p) {
    while (count_zero(x - 1) == p && x > 1)  x --;
    out << x;
}

void binary_search(int p, int st, int dr) {
    while (st <= dr) {
        int mij = (st + dr) / 2;
        int x = count_zero(mij);
        if (x == p) {
            fin(mij, p);
            return ;
        } else if (x > p) {
            dr = mij - 1;
        } else {
            st = mij + 1;
        }
    }
}

int main() {
    int p;
    in >> p;
    binary_search(p, 1, 500000000);
    return 0;
}