Cod sursa(job #3201594)

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