Pagini recente » Cod sursa (job #2085467) | Cod sursa (job #2489053) | Cod sursa (job #2466719) | Cod sursa (job #2312640) | Cod sursa (job #2614213)
#include <iostream>
#include <fstream>
std::ifstream f("fact.in");
std::ofstream g("fact.out");
int findTrailingZeros(int n)
{
// Initialize result
int count = 0;
// Keep dividing n by powers of
// 5 and update count
for (int i = 5; n / i >= 1; i *= 5)
count += n / i;
return count;
}
int main()
{
int p;
f >> p;
if (p == 0)
{
g << "1";
return 0;
}
int n = 5 * p;
int nb_of5 = findTrailingZeros(n);
if (nb_of5 == p)
{
g << n;
return 0;
}
else
{
while (1)
{
int temp = n;
do
{
temp /= 5;
nb_of5--;
} while (temp % 5 == 0);
if (nb_of5 == p)
{
g << n;
return 0;
}
if (nb_of5 < p)
{
g << "-1";
return 0;
}
n -= 5;
}
}
}