Cod sursa(job #1667500)

Utilizator IutucuIstrate Paul Ioan Iutucu Data 28 martie 2016 23:02:50
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 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=-2;
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;
}