Cod sursa(job #1667501)

Utilizator IutucuIstrate Paul Ioan Iutucu Data 28 martie 2016 23:03:54
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <iostream>
#include <fstream>
#include<climits>
using namespace std;
long int  verificare(long int n)
{
    long nr_zero;
    nr_zero=0;
    while(n/5)
    {
        nr_zero+=n/5;
        n/=5;
    }
    return nr_zero;
}
int main()
{
    ifstream in ("fact.in");
    ofstream out ("fact.out");
    long  p=;
long  mij,li=0,ls=LONG_MAX;
    bool  gasit=false;
    in>>p;
    while((li<=ls)&&(!gasit)&&p>=0)
    {
        mij=(li+ls)/2;
    if((verificare(mij)==p&&verificare(mij-1)<p)||mij<5)
        {
            if (mij<5)
                cout<< 1 <<"\n";
            else
                cout<< mij <<"\n";
            gasit=1;
        }
    else
        if(verificare(mij)<p)
            li=mij+1;
        else ls=mij-1;
    }
    if (gasit==0)
        out<<-1;
return 0;
}