Cod sursa(job #2624416)

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

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

long caut(long x) {
    long st = 1, dr = 5 * x, 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");
    long p, nr;
    cin >> p;
    if(p == 0)
        cout << 1;
    else {
        nr = caut(p);
        nr -= nr % 5;
         cout << nr;
    }
    return 0;
}