Pagini recente » Cod sursa (job #2912947) | Cod sursa (job #2553305) | Cod sursa (job #2490379) | Cod sursa (job #1944450) | Cod sursa (job #615200)
Cod sursa(job #615200)
#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,500000000)*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)
{
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);
}