Pagini recente » Mihai Tenea | Profil jeffpascal | Istoria paginii runda/1111/clasament | Cod sursa (job #2018391) | Cod sursa (job #2636636)
#include<fstream>
#include<iostream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int numOf5(int a)
{
int b = 0;
while (a % 5 == 0 && a != 0)
{
b++;
a /= 5;
}
return b;
}
int biggest(int a)
{
int s = 5;
while (s < a)
{
s *= 5;
}
return s / 5;
}
int main()
{
int n,p = 0, s = 25;
f >> n;
if (n == 0)
{
g << 1;
return 0;
}
/*while (p < n)
{
p += numOf5(s / 5) + 5;
s += 25;
}
s -= 25;
*/
p = n;
s = n * 5;
int s1 = s;
int b = biggest(s);
while (b % 25 == 0)
{
p += s / b;
b /= 5;
}
while (p > n)
{
p -= numOf5(s / 5) + 1;
s -= 5;
}
if (p == n)
g << s;
else
g << -1;
return 0;
}