Pagini recente » Cod sursa (job #849742) | Cod sursa (job #387104) | Cod sursa (job #60221) | Cod sursa (job #288446)
Cod sursa(job #288446)
#include <fstream.h>
ifstream f("fact.in");
ofstream g("fact.out");
long p;
long fact (long n)
{ long nr_0=0,aux;
for (long i=5; i<=n; i+=5)
{ aux=i;
while (aux%5==0)
{ nr_0++; aux/=5; } }
return nr_0;
}
int caut_bin(long val)
{
long i, step;
for (step = 1; step < 10000; step <<= 1);
for (i = 0; step; step >>= 1)
if (i + step <= 10000 && fact (i + step) <= val)
i += step;
if (i) return i;
else return -1;
}
int main ()
{ f>>p;
long aux=caut_bin(p);
aux=aux-(aux%5);
g<<aux;
return 0;
}