Cod sursa(job #3204436)

Utilizator TeodorVTeodorV TeodorV Data 16 februarie 2024 18:41:23
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

int getNr0(long long n)
{
    long long p5=5;
    int rez=0;
    while(n/p5>0)
    {
        rez+=n/p5;
        p5*=5;
    }
    return rez;
}

int cb(int x)
{
    int st=1,dr=1e9,mij;
    while(st<=dr)
    {
        mij=(st+dr)/2;
        int nr0=getNr0(mij);
        if(nr0==x)
            return mij;
        if(nr0<x)
            st=mij+1;
        else dr=mij-1;
    }
    return -1;
}

int main()
{
    int p;
    fin>>p;
    int ind=cb(p);
    if(ind==-1)
        fout<<-1;
    else
    {
        ind-=ind%5;
        if(ind==0)
            ind=1;
        fout<<ind;
    }
    return 0;
}