Cod sursa(job #2760378)

Utilizator mihnea03Ciocioiu Mihnea mihnea03 Data 25 iunie 2021 19:26:33
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <fstream>

using namespace std;
long long n,st,dr;

int main() {
    ifstream fin("fact.in");
    ofstream fout("fact.out");
    fin>>n;
    st=1;
    dr=n*5;
    while (st<=dr) {
        long long mid=(st+dr)/2;
        long long nr=mid;
        long long sol=0;
        long long m=5;
        while (nr>=m) {
            sol+=nr/m;
            m*=5;
        }
        if (sol>=n) {
            dr=mid-1;
        }
        else {
            st=mid+1;
        }
    }
    fout<<st;
    return 0;
}