Cod sursa(job #2755561)

Utilizator redalert12oanea alex redalert12 Data 27 mai 2021 17:24:50
Problema Factorial Scor 45
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int p,nr ;
bool ok =0;
int count5(int nr)
{
    int s=0;
    int x=5;
    while(x<=nr)
    {
        s+=nr/x;
        x*=5;
    }

    return s;
}

int cautare_binara(int st,int dr,int x)
{
    int m=0;
    while (st<=dr)
    {
        m=(st+dr)/2;
        int mij=count5(m);
       // cout<<"mij="<<mij<<endl;
        //cout<<"m="<<m<<endl;
        if (mij==x) return m;
        if (mij<x)
        {
            st=m+1;
        }
        else
            dr=m-1;
    }

    return -1;

}
int main()
{
    int n;

    nr=0;
    ok=0;
    in>>p;
    if (p==0)
        {
        out<<1;
        }else
    out<<cautare_binara(1,5*p,p);

    return 0;

}