Cod sursa(job #2077908)

Utilizator Andrei243Nitu Mandel Andrei Andrei243 Data 28 noiembrie 2017 18:31:58
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <iostream>
#include <algorithm>
#include <fstream>

using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
unsigned int n;



unsigned int nr_0(unsigned int n){
unsigned int nr_0uri=0;
unsigned int i=5;
while(n/i>0){
nr_0uri+=n/i;
i*=5;

}
return nr_0uri;
}

void bsearch0 (unsigned int st, unsigned int dr, unsigned int x) {
    unsigned int m=st+(dr-st)/2;

    while (nr_0(m)!=x && st <= dr) {
        m = st +( dr-st) / 2;
        if (nr_0(m) > x)
            dr = m-1;
        else
            st = m+1;
    }
    while (nr_0(m-1) == nr_0(m))m--;
        if(nr_0(m)==x) out<<m;
    else out<< -1;
}



int main()
{in>>n;
if(n==0)out<<1;
else bsearch0(1,100000000,n);

    return 0;
}