Cod sursa(job #2988802)

Utilizator Thomas_Paturan114Paturan Thomas Thomas_Paturan114 Data 5 martie 2023 14:51:20
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int main()
{
    long long n, st, dr, mij, c, z, r = -1;
    fin >> n;
    st = 1;
    dr = INT_MAX;
    while(st <= dr)
    {
        mij = st + (dr - st) / 2;
        c = 5;
        z = 0;
        while(c <= mij)
        {
            z += mij / c;
            c *= 5;
        }
        if(z >= n)
        {
            r = mij;
            dr = mij - 1;
        }
        else
            st = mij + 1;
    }
    fout << r;
}