Cod sursa(job #1943940)

Utilizator rauliacobanRaul Iacoban rauliacoban Data 28 martie 2017 21:28:16
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
/*
www.infoarena.ro/problema/fact
*/
#include<fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");

int zero(int x)
{
    int exp=5,t=0;
    while(x/exp)
    {
        t+=x/exp;
        exp*=5;
    }
    return t;
}

int main()
{
    int p,l=1,r=1000000000,mid,sol=-1,x;
    fin>>p;
    while(l<=r)
    {
        mid=(l+r)/2;
        x=zero(mid);
        if(x<p)
            l=mid+1;
        else
            if(x>p)
                r=mid-1;
            else
            {
                sol=mid;
                r=mid-1;
            }
    }
    fout<<sol<<'\n';

    fin.close();
    fout.close();
    return 0;

}