Pagini recente » Cod sursa (job #946577) | Cod sursa (job #876369) | Cod sursa (job #292481) | Cod sursa (job #2530960) | Cod sursa (job #1027650)
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
long long P, step, N, Z, temp, nr, i, nr1;
long fact(long long N)
{ long long Z = 0, temp = 5;
while ( temp <= N )
{
Z += N / temp;
temp *= 5;
}
// if
return Z;
}
int main()
{
in >> P;
if ( !P ) out << 1;
else
{
step = 1ll<<30;
for ( i = 0; step; step >>= 1 )
{
//cout << step << " " << fact(step) << '\n';
if ( fact(i+step) <= P )
{
i += step;
}
}
if ( fact(i) != P ) out << -1;
else
out << i - (i % 5);
}
return 0;
}