Cod sursa(job #2345384)

Utilizator chiravladChira Vlad chiravlad Data 16 februarie 2019 12:10:09
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <cstdio>
const int right = 1000000001;

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

    for(int i=5; n/i>=1; i=i*5)
    {
        count1 += n/i;
    }
    return count1;*/
    int p=5;
    int power =0;
    int cp=p;
    while((n/cp) > 0 )
    {
        power = power + n/cp;
        cp = cp * p;
    }
    return power;

}

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;
}