Cod sursa(job #76339)

Utilizator recviemAlexandru Pana recviem Data 9 august 2007 15:34:07
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#include <fstream.h>

using namespace std;

        ifstream input("fact.in");
        ofstream output("fact.out");
        int p;

int citire ()
{
        input >> p;
        input.close();
        return 0;
}

int verif(int x)
{
        int rez=0;
        while (x >= 5)
        {
                rez = rez + x / 5;
                x = x / 5;
        }
        return rez;
}

int cautarebin(int a,int b)
{
        int x,val;
        bool gasit=false;

        while ((a < b) && (a != b))
        {
                x=(a+b)/2;
                x = x-(x%5);
                val=verif(x);
                if (val == p)
                {
                        output << x;
                        gasit=true;
                        break;
                } else
                if (val < p)
                {
                        a=(a+b)/2;
                } else
                {
                        b=(a+b)/2;
                }

        }
        if (! gasit) output << "-1";
        return 0;
}

int main(int argc, char* argv[])
{
        citire();
        if (p==0) output << "1";
                else cautarebin(0,100);
        output.close();
        return 0;
}
//---------------------------------------------------------------------------