Cod sursa(job #2623878)

Utilizator ioanapintilie07Pintilie Ioana ioanapintilie07 Data 4 iunie 2020 02:55:54
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;

int nrzero(int x) {
    int p = 5, nz = 0;
    while (x / p != 0) {
        nz += x / p;
        p *= 5;
    }
    return nz;
}

int caut(int x) {
    long long st = 1, dr = pow(x, 10), m, nz;
    while (st <= dr) {
        m = (st + dr) / 2;
        nz = nrzero(m);
        if (nz == x)
            return m;
        if (nz < x)
            st = m + 1;
        else
            dr = m - 1;
    }
    return -1;
}

int main() {
    ifstream fin("fact.in");
    ofstream fout("fact.out");
    int p, nr;
    fin >> p;
    nr = caut(p);
    nr -= nr % 5;
    fout << nr;
    return 0;
}