Pagini recente » Cod sursa (job #2475428) | Cod sursa (job #1136369) | Cod sursa (job #2366797) | Cod sursa (job #686813) | Cod sursa (job #615203)
Cod sursa(job #615203)
#include <fstream>
using namespace std;
int calc(unsigned long h);
int binary(unsigned long start, unsigned long end);
unsigned long p,no;
int main()
{
ifstream f ("fact.in");
ofstream g ("fact.out");
f>>p;
f.close ();
no = binary(0,2000000000)*5;
if (!no)
g<<"-1";
else g<<no;
g.close ();
return 0;
}
int calc(unsigned long h)
{
unsigned long sum = h;
while (h>4)
{
sum = sum + h/5;
h = h/5;
}
return sum;
}
int binary(unsigned long start, unsigned long end)
{
if (start>end) return 0;
else {
unsigned long k = (start + end) /2;
if (calc(k) == p) return k;
if (calc(k) < p) return binary (k+1,end);
else return binary (start,k-1);
}
}