Pagini recente » Cod sursa (job #702857) | Cod sursa (job #2542212) | Cod sursa (job #1693994) | Cod sursa (job #1748266) | Cod sursa (job #2785438)
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int main()
{
int p;
fin >> p;
int p5 = 1,p5i=0;
int x = 5,y,xi;
while (p5 < p)
{
p5i = p5;
p5 = p5 * 5 + 1;
x = x * 5;
}
if (p == 0)
fout << 1;
else
if (p5 == p)
fout << x;
else
if(p5-p<=p-p5i)
{
p5 = (p5-1)/5;
x = x / 5;
while (p5 < p)
{
x = x + 5;
y = x;
while (y % 5 == 0)
{
p5++;
y = y / 5;
}
}
if (p5 > p)
fout << -1;
else
fout << x;
}
else
{
p5i = p5;
xi = x;
while (p5i > p)
{
y = xi;
while (y % 5 == 0)
{
p5i--;
y = y / 5;
}
xi = xi - 5;
}
if (p5i < p)
fout << -1;
else
fout << xi;
}
}