Cod sursa(job #1293199)

Utilizator adnionutCojocaru Ionut adnionut Data 15 decembrie 2014 16:11:55
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <fstream>
#include <climits>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long p,st,dr,m,nr,k,ok;
int main()
{
    f>>p;
    st=0;
    dr=LLONG_MAX;
    ok=0;
    while(st<=dr)
    {
        m=(st+dr)/2;
        nr=0;
        k=5;
        while(k<=m)
        {
            nr+=m/k;
            k*=5;
        }
        if(p<=nr)
            dr=m-1;
        else
            st=m+1;
        if(p==nr)
            ok=1;
    }
    if(ok==0)
        g<<"-1";
    else
        if(st==0)
            g<<"1";
        else
            g<<st;
    return 0;
}