Cod sursa(job #2740411)

Utilizator DragosC1Dragos DragosC1 Data 12 aprilie 2021 21:27:22
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;

int n, poz = -1;

void read() {
    ifstream f("fact.in");
    f >> n;
    f.close();
}

int verifica(int x) {
    int i, zeros = 0;
    for (i = 244140625; i >= 5; i /= 5) 
        zeros += x / i;
    return zeros;
}

void solve() {
    int st, dr, mij, x;
    st = 1, dr = 500000000;
    while (st <= dr) {
        mij = (st + dr) / 2;
        x = verifica(mij);
        if (x >= n) {
            if (x == n)
                poz = mij;
            dr = mij - 1;
        }
        else st = mij + 1;
    }
}

void output() {
    ofstream g("fact.out");
    g << poz;
    g.close();
}

int main() {
    read();
    solve();
    output();
    return 0;
}