Cod sursa(job #2448154)

Utilizator nTropicGravityesadasdwaadwqafr nTropicGravity Data 15 august 2019 22:03:30
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include    <fstream>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

#define MAX_N 500000000

#define MIN_N 1

int P;

int findTrailingZeros(int N) {
    int counter = 0;

    for (int i = 5; N / i > 0; i *= 5)
        counter += N / i;

    return counter;
}

int binSearch(int Left, int Right, int P) {
    int Mid, Result = - 1;

    while (Left <= Right) {
        Mid = (Left + Right) / 2;

        if (findTrailingZeros(Mid) == P)
            Result = Mid;

        if (findTrailingZeros(Mid) < P)
            Left = Mid + 1;

        else
            Right = Mid - 1;
    }

    return Result;
}

int main() {
    fin >> P;
    fout << binSearch(MIN_N, MAX_N, P);
}