Cod sursa(job #2656491)

Utilizator Razvan48Capatina Razvan Nicolae Razvan48 Data 7 octombrie 2020 20:53:15
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <fstream>
#include <climits>

using namespace std;

long long maxim = INT_MAX - 1;
long long last = -1;
long long p;
long long nrCif;

void sol(long long val)
{
    nrCif = 0;

    for(long long x = 5; x <= val; x = x * 5)
    {
        nrCif += val / x;
    }
}

void bin()
{
    long long st = 1;
    long long dr = maxim;

    while (st <= dr)
    {
        long long mij = (st + dr) / 2;
        sol(mij);
        if (nrCif == p)
        {
            last = mij;
            dr = mij - 1;
        }
        else if (nrCif > p)
        {
            dr = mij - 1;
        }
        else
        {
            st = mij + 1;
        }
    }
}

int main()
{
    ifstream in("fact.in");
    ofstream out("fact.out");

    in >> p;
    bin();

    out << last;

    return 0;
}