Pagini recente » Cod sursa (job #541855) | Cod sursa (job #491669) | Cod sursa (job #2083555) | Cod sursa (job #147261) | Cod sursa (job #1156538)
#include <cstdio>
using namespace std;
const int MAX=2000000000;
int fact(int x);
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
int p;
scanf("%d",&p);
if(p==0)
{
printf("1\n");
return 0;
}
int dr;
dr=fact(MAX);
int i, step;
for (step = 1; step < dr; step <<= 1);
for (i = 0; step; step >>= 1)
if (fact(i + step)< dr && fact(i+step)<=p)
i += step;
if(i)
{
while(i%5)i--;
printf("%d\n",i);
}
else
printf("-1\n");
return 0;
}
int fact(int x)
{
int a=5,rez=0;
while(x/a)
{
rez+=x/a;
a*=5;
}
return rez;
}