Cod sursa(job #3170360)

Utilizator CalinHanguCalinHangu CalinHangu Data 17 noiembrie 2023 14:55:57
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int sol(int n) {
    int p=1, cnt=0;
    while (p < n)
    {
        p *= 5;
        cnt += n / p;
    }
    return cnt;
}
int main() {
    int p;
    int mij, st, dr, x;
    fin >> p;
    st = 1; dr = 2147483646; x = -1;
    while (st <= dr) {
        mij = (st + dr) / 2;
        if (sol(mij) == p)
            x = mij;
        if (sol(mij) >= p)
            dr = mij - 1;
        else
            st = mij + 1;
    }
    fout <<x;
}