Pagini recente » Cod sursa (job #2986205) | Cod sursa (job #2294281) | Cod sursa (job #1112733) | Cod sursa (job #461658) | Cod sursa (job #1027635)
#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 >= 5; 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;
}