Cod sursa(job #3201587)

Utilizator Theo20067Cismaru Theodor-Alexe Theo20067 Data 9 februarie 2024 09:07:29
Problema Factorial Scor 25
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>
using namespace std;
ifstream fin ("fact.in");
ofstream fout("fact.out");
long long st,dr,p,mid;
long long zero(long long x)
{
    long long l=5;
    long long c=x;
    long long nr=0;
    while(c>l)
    {
        nr+=c/l;
        l*=5;
    }
    return nr;
}
int main()
{
    fin>>p;
    st=1;
    dr=1e17;
    while(st<=dr)
    {
        mid=(st+dr)/2;
        if(zero(mid)==p)
        {
            st=mid;
            break;
        }
        if(zero(mid)>p)
            dr=mid-1;
        else
            st=mid+1;
    }
    if(zero(st)!=p)
        fout<<-1;
    else
        fout<<st;
    return 0;
}