Pagini recente » Cod sursa (job #2930478) | Cod sursa (job #2973610) | Cod sursa (job #2813024) | Cod sursa (job #1177627) | Cod sursa (job #1027505)
#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 long fact(long long N)
{ long long a, b;
a = N / 5;
b = log(a)/log(5);
return b;
}
int main()
{
in >> P;
if ( !P ) out << 1;
else {
step = 1ll<<30;
for ( ; step >= 5; step >>= 1 )
{
N = step;
Z = N / 5;
nr = log(Z)/log(5);
Z += nr;
// cout << N << " " << fact(N) << " " << Z << '\n';
if ( Z <= P )
{
if ( Z == P ) { out << N - (N % 5); break; }
else
{
N = N + (P - Z)*5;
if ( nr != fact(step) ) N -= 5;
out << N - (N % 5);
break;
}
}
}
}
return 0;
}