Cod sursa(job #2345373)

Utilizator chiravladChira Vlad chiravlad Data 16 februarie 2019 12:01:22
Problema Factorial Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <cstdio>
const int right = 100000001;

int ok(int n)
{
    int count1 = 0;

    for(int i=5; n/i>=1; i=i*5)
    {
        count1 += n/i;
    }
    return count1;
}

int binarySearch_Left(int st, int dr,int x)
{
    int med, last =-1;
    while(st<=dr)
    {
        med = st + (dr-st)/2;
        if(ok(med) == x)
        {
            last = med;
            dr = med -1;
        }
        else if(x < ok(med))
        {
            dr = med - 1;
        } else st = med + 1;
    }
    return last;
}

int main()
{
    freopen("fact.in","r",stdin);
    freopen("fact.out","w",stdout);
    int p;
    scanf("%d%d",&p);
    printf("%d",binarySearch_Left(1,right,p));
    return 0;
}