Cod sursa(job #3003496)

Utilizator ShadowZoidPorojan Victor-Andrei ShadowZoid Data 15 martie 2023 19:20:49
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("fact.in");
ofstream cout("fact.out");
int n,m,i,v[1005],mij,st,dr,g,p;
int nrzero(int n)
{
    int nr=0;
    while(n>=5)
    {
        nr+=n/5;
        n/=5;
    }
    return nr;
}
int main()
{
    cin>>p;
    st=0;
    dr=5e8;
    g=dr+1;
    while(st<=dr)
    {
        mij=(st+dr)/2;
        if(nrzero(mij)>=p)
        {
            dr=mij-1;
            g=mij;
        }
        else
            st=mij+1;
    }
    if(g==0)
        cout<<1;
    else
        cout<<g;
    return 0;
}