Cod sursa(job #1667301)

Utilizator IutucuIstrate Paul Ioan Iutucu Data 28 martie 2016 20:31:42
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>
#define intm 32000
using namespace std;

long verificare(int n)
{
    long nr_zero;
    nr_zero=0;
    while(n/5)
    {
        nr_zero+=n/5;
        n/=5;
    }
    return nr_zero;
}
long p;
int main()
{
    ifstream in ("fact.in");
    ofstream out ("fact.out");
    long mij,li=0,ls=intm;
    bool gasit;
    in>>p;
    while((li<=ls)&&(!gasit))
    {
        mij=(li+ls)/2;
    if(verificare(mij)==p&&verificare(mij-1)<p)
        {
            out<<mij;
            gasit=1;
        }
    else
        if(verificare(mij)<p)
            li=mij+1;
        else ls=mij-1;
    }
if(gasit==0)
    out<<mij;
}