Cod sursa(job #1667350)

Utilizator IutucuIstrate Paul Ioan Iutucu Data 28 martie 2016 21:07:52
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream in ("fact.in");
ofstream out ("fact.out");
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()
{
    long int p;
    long int mij,li=0,ls=32000;
    bool  gasit;
    in>>p;
    while((li<=ls)&&(!gasit))
    {
        mij=(li+ls)/2;
    if(verificare(mij)==p&&verificare(mij-1)<p||mij<5)
        {
            if (mij<5)
                out<<"1";
            else
                out<<mij;
            gasit=1;
        }
    else
        if(verificare(mij)<p)
            li=mij+1;
        else ls=mij-1;
    }
if(gasit==0)
    out<<mij;
return 0;
}