Cod sursa(job #2793315)

Utilizator christalknightChristian Micea christalknight Data 3 noiembrie 2021 14:25:22
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

unsigned long long binary_srch(unsigned long long P, unsigned long long high, unsigned long long low);

int main()
{
    unsigned long long P, high;
    cin>>P;
    if(!P)
        cout<<1;
    else{
        high = P * 5 + P / 5;
        cout<<binary_srch(P, high, 1);
        }
}

unsigned long long binary_srch(unsigned long long P, unsigned long long high, unsigned long long low){
    unsigned long long mid, nr_cerut = 0, i_copie, i;
    mid = (high + low) / 2 + 1;
    for(i = 1; i <= mid; i += 5){
        i_copie = i;
        while(i_copie % 5 == 0){
            i_copie /= 5;
            nr_cerut++;
            }
        if(i == 1)
            i--;
        }
    if(nr_cerut == P)
        return i - 5;
    else if(nr_cerut > P)
        return binary_srch(P, mid, low);
    else return binary_srch(P, high, mid);
    }