Cod sursa(job #2668913)

Utilizator sims_glAlexandru Simion sims_gl Data 5 noiembrie 2020 18:00:09
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<iostream>
#include<fstream>
using namespace std;
int p;

int n(int x)
{
    int d=5,rez=0;
    while(d<=x)
    {
        rez+=x/d;
        d=d*5;
    }
    return rez;
}
int cautarebinara(int p)
{
    if(p==0)
        return 1;
    int st=1;
    int dr=p*5;
    while(st<=dr )
    {

        int mij=(st+dr)/2;
        if(n(mij)>p)
        {
            dr=mij-1;
        }
        else if(n(mij)<p)
        {
            st=mij+1;
        }
        else if(n(mij-1)<p){
                return mij;
        }
        else dr=mij-1;
    }
    return -1;
}
int main()
{
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);
    cin>>p;
    cout<<cautarebinara(p);
}