Cod sursa(job #2077903)

Utilizator horea4Cenan Horea horea4 Data 28 noiembrie 2017 18:29:05
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("fract.in");
ofstream fout("fract.out");
int cont=0;
bool ok;
int p;
unsigned long long dr=LONG_MAX,mid,st;
int nr(int a)
{
    int c=0;
    int ca=a;
    while(ca>0)
    {
        c=c+ca/5;
        ca=ca/5;
    }
    return c;
}
void cbin()
{   cont++;
    if(cont>33 && ok==0)
    {   ok=1;
        fout<<"-1";
        return;
    }
    if(ok==1)return;
    mid=(st+dr)/2;
   if(nr(mid)==p)
   {   while(mid%5!=0)mid--;
       fout<<mid;
       return;
   }

   if(nr(mid)>p)
   {
       dr=mid+1;
       cbin();
   }
   if(nr(mid)<p)
   {
       st=mid-1;
       cbin();
   }
}
int main()
{
fin>>p;
if(p==0){fout<<1;return 0;}

cbin();
    return 0;
}