Cod sursa(job #1097759)

Utilizator terrorturtle01Ion George Mihai terrorturtle01 Data 3 februarie 2014 21:51:05
Problema Factorial Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <fstream>
using namespace std;
long p, n;

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

int find_N(long x, long r){
    if(x > r){
        return -1;
    }else{
        long c = (x+r)/2;
        if(fx(c)<p){
            find_N(c, r);
        }else if(fx(c)>p){
            find_N(x, c-1);
        }else{
            return c;
        }
    }
}

int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
    f>>p;
    if(p == 0){
        g<<1;
    }else{
        n = find_N(0, 5000000000);
        while(fx(n-1)==p){
            n=n-1;
        }
    }
    g<<n;
}