Cod sursa(job #1107139)

Utilizator terrorturtle01Ion George Mihai terrorturtle01 Data 13 februarie 2014 17:28:13
Problema Factorial Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
using namespace std;
int P, nrz, N;

int zero(int k){
    long m = 5;
    int z = 0;
    while(k/m != 0){
        z+=k/m;
        m*=5;
    }
    return z;
}

int bin_search(int a, int b){
    int c;
    c = (a+b)/2;
    if(zero(c) < P)
        bin_search(c+1, b);
            else if(zero(c) > P)
                bin_search(a, c-1);
                    else if(zero(c) == P)
                        return c;
                            else
                                return -1;
}

int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
    f>>P;
    if(P==0){
        g<<1;
    }else{
        long n = bin_search(0, 500000000);
        g<<n-1;
    }
    return 0;
}