Cod sursa(job #3194999)

Utilizator Cezar2009Cezar Mihai Titihazan Cezar2009 Data 19 ianuarie 2024 21:42:51
Problema Factorial Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.55 kb
//https://infoarena.ro/problema/fact
#include <bits/stdc++.h>
using namespace std;

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

int main()
{
    long long p;
    fin>>p;
    long long l=1,r=100000000;
    while (l<=r)
    {
        long long mm=(l+r)/2;
        long long c5=5,sum=0;
        while(c5<=mm)
        {
            sum+=mm/c5;
            c5*=5;
        }
        if(sum>=p)
        {
            r=mm-1;
        }
        else
        {
            l=mm+1;
        }
    }
    fout<<l;

    return 0;
}