Cod sursa(job #2364386)

Utilizator herbiculusMihai Panduru herbiculus Data 4 martie 2019 02:20:23
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long p,st=1,dr=9223372036854775807,mid,howmany,retine;
long zero(long x)
{
    int many=0;
    while (x>0)
    {
        many+=x/5;
        x/=5;
    }
    return many;
}
int main()
{
    f>>p;
    if (!p)
        g<<"1";
    else
    {
        while (st<=dr)
        {
            mid=(st+dr)/2;
            howmany=zero(mid);
            if (howmany==p)
            {
                retine=mid;
                dr=mid-1;
            }
            else if (howmany<p)
                st=mid+1;
            else
                dr=mid-1;
        }
        g<<(retine>0?retine:-1);
    }
}