Pagini recente » Cod sursa (job #3179414) | Cod sursa (job #1950966) | Cod sursa (job #200797) | Cod sursa (job #286831) | Cod sursa (job #1156549)
#include <cstdio>
using namespace std;
const int MAX=1000000000;
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;
}
bool ok=false;
int dr=fact(MAX);
int i, step;
for (step = 1; step <= dr; step <<= 1);
for (i = 0; step; step >>= 1)
if (fact(i+step)<= dr and fact(i+step)<=p){
if(fact(i+step)==p)ok=true;
i += step;
}
if(i and ok)
{
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;
}