Cod sursa(job #2986828)

Utilizator tudorp_Pop Tudor tudorp_ Data 1 martie 2023 12:27:05
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p,l,r,m,e,x,s;
bool ok=1;
int main()
{
    fin>>p;
    l=1;
    r=100000005;
    if (p==0)
    {
        fout<<1;
    }

    else
    {
        while (l<=r && ok)
        {
            m=(l+r)/2;
            e=0;
            x=m;
            while (x>0)
            {
                e+=x;
                x/=5;
            }
            if (e<p)
            {
                l=m+1;
            }
            else if (e>p)
            {
                r=m-1;
            }
            else
            {
                ok=0;
                s=m*5;
            }
        }
        if (ok)
            fout<<-1;
        else fout<<s;
    }
    return 0;
}