Cod sursa(job #1171185)

Utilizator dianaa21Diana Pislaru dianaa21 Data 15 aprilie 2014 13:01:44
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>
using namespace std;
ifstream is ("fact.in");
ofstream os ("fact.out");

int p;
int C(int a, int b);
int Nrz(int x);
int main()
{
    is >> p;
    if(p > 4)
        os << C(1, p*5);

    else
    {
        if(p == 0)
            os << 1;
        else
            os << p*5;
    }


    is.close();
    os.close();
    return 0;
}
int C(int a, int b)
{
    if(a > b)
        return -1;
    else
    {
        int m = (a+b)/2;
        if(p == Nrz(a))
            return a;
        if(p > Nrz(m))
            return C(m+1, b);
        if(p <= Nrz(m))
            return C(a, m);
    }
}
int Nrz(int x)
{
    x /= 5;
    int S = x;
    while(x > 5)
    {
        x/=5;
        S+=x;
    }
    if(x == 5)
        S+=1;
    return S;
}