Cod sursa(job #1687850)

Utilizator razvan99hHorhat Razvan razvan99h Data 13 aprilie 2016 09:22:42
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long n, p, ok;

long long cati_0(long long x)
{   long long nr=0;
    while(x/5)
    {   nr=nr+x/5;
        x=x/5;
    }
    return nr;
}
int caut_bin()
{   long long st=1, dr=(1LL<<63)-2, mij, x;
    while(st<=dr)
    {   mij=(st+dr)/2;
        x=cati_0(mij);
        if(x==p)
        {   ok=1;
            return mij;
        }
        if(x<p)
            st=mij+1;
        else dr=mij-1;
    }
}

int main()
{   f>>p;
    n=caut_bin();
    if(ok==1)
    {   while(n%5) n--;
        g<<n;
    }
    else g<<-1;
    return 0;

}