Cod sursa(job #2612025)

Utilizator buhaidarius@gmail.comBuhai Darius [email protected] Data 7 mai 2020 23:42:08
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <iostream>
#include <fstream>

using namespace std;

long nr_0(long x){
    long pow = 5, nr = 0;
    while(x/pow>0){
        nr+=x/pow;
        pow*=5;
    }
    return nr;
}

int caut_binar(int l, int r,int p){
    if(l>r) return -1;
    int md = l+(r-l)/2, nr = nr_0(md);
    if(nr==p){
        while(nr_0(--md)==p);
        return md+1;
    }
    if(nr>p) return caut_binar(l, md, p);
    return caut_binar(md+1, r, p);
}

int main() {
    ifstream fin("fact.in");
    ofstream fout("fact.out");
    long p;
    fin>>p;
    if(p==0) fout<<1;
    else
        fout<<caut_binar(1, p*10, p);
    return 0;
}