Cod sursa(job #3201593)

Utilizator Theo20067Cismaru Theodor-Alexe Theo20067 Data 9 februarie 2024 09:16:56
Problema Factorial Scor 80
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=2e8;
    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;
}