Cod sursa(job #3350583)

Utilizator VLADIMIR_NNiculici Vladimir Andrei VLADIMIR_N Data 10 aprilie 2026 11:06:28
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <fstream>
using namespace std;
ifstream fin ("fact.in");
ofstream fout ("fact.out");
int main()
{
    int p,n=-1,st=1,dr=2e9,mid;
    fin >> p;
    while (st<=dr)
    {
        mid=(st+dr)/2;
        int nrz=0,p5=1;
        while (p5*5<=mid)
        {
            p5*=5;
            nrz+=mid/p5;
        }
        if (nrz>p)
        {
            dr=mid-1;
        }
        if (nrz==p)
        {
            dr=mid-1;
            n=mid;
        }
        if (nrz<p)
        {
            st=mid+1;
        }
    }
    fout << n;
    return 0;
}