Pagini recente » Cod sursa (job #361269) | Cod sursa (job #2743548) | Cod sursa (job #1031694) | Cod sursa (job #1153418) | Cod sursa (job #756063)
Cod sursa(job #756063)
#include <cstdio>
using namespace std;
FILE *f = fopen ("fact.in","r");
FILE *g = fopen ("fact.out","w");
int main()
{
int P, cnt = 0, sol, i, ok = 1;
fscanf (f, "%d", &P);
if (P == 0)
sol = 1;
else if (P < 5 && P != 0)
sol = 5 * P;
else
{
for (i = 5; cnt < P; i += 5)
{
cnt += 4;
int j = i;
while (j % 5 == 0)
{
cnt++;
j /= 5;
}
cnt++;
}
i -= 5;
if (cnt > P)
{
while (cnt != P && ok)
{
int j = i;
while (j % 5 == 0)
{
cnt--;
j /= 5;
}
i--; cnt--;
if (cnt < P)
ok = 0;
}
}
else
{
while (cnt != P && ok)
{
int j = i;
while (j % 5 ==0)
{
cnt--;
j /= 5;
}
i++; cnt--;
if (cnt > P)
ok =0;
}
}
if (ok)
sol = 5 * i;
else
sol = -1;
}
fprintf (g, "%d\n", sol);
fclose(f);
fclose(g);
return 0;
}