Cod sursa(job #1213565)

Utilizator rangerChihai Mihai ranger Data 28 iulie 2014 15:34:33
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include<fstream>
#define LL long long
using namespace std;
ifstream cin("fact.in");
ofstream cout("fact.out");
LL p,n;
LL nr0(LL x)
{
    LL c=0,k=5;
    while (k<=x)
    {
        c+=x/k;
        k*=5;
    }
    return c;
}
int CautBin(LL l,LL r)
{
    if (l>r) return -1;
    int m=(l+r)/2, x=nr0(m);
    if (x==p) return m;
    if (x>p) return CautBin(l,m-1);
       else return CautBin(m+1,r);
}
int main()
{
    cin>>p;
    LL c=CautBin(1,20000000000);
    if (p==0) {cout<<1; return 0;}
    if(c==-1) {cout<<c; return 0;}
    while (c%5) c--;
    cout<<c;
    return 0;
}