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