Pagini recente » Cod sursa (job #274786) | Cod sursa (job #509686) | Cod sursa (job #1267703) | Cod sursa (job #3166463) | Cod sursa (job #2857647)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int n, ans, pow2 = (1 << 24);
int p5(int x)
{
int sol = 0, i = 5;
while(i < x)
{
sol += x / i;
i = i * 5;
}
//fout << x << ' ' << sol << '\n';
return sol;
}
void solve(int x)
{
//fin >> x;
ans = 0;
for(int i = pow2; i > 0; i >>= 1)
{
if(p5(ans + i) < x)
ans += i;
}
if(p5(ans + 1) == x)
fout << ans + 1 << '\n';
else
fout << -1;
}
int main()
{
fin >> n;
//for(int i = 1; i <= 10000; i++)
solve(n);
return 0;
}