Pagini recente » Cod sursa (job #1947542) | Cod sursa (job #3261598) | Cod sursa (job #211816) | Cod sursa (job #24758) | Cod sursa (job #2557647)
#include <fstream>
#include <cmath>
using namespace std;
ifstream cin("fact.in");
ofstream cout("fact.out");
int zeros(int n)
{
int ans=0;
while(n)
{
ans+=(n/5);
n/=5;
}
return ans;
}
int getBiggestBit(int n) {
int sol = 1;
while (n) {
sol += 1;
n >>= 1;
}
return sol;
}
int main()
{
int p,n;
cin>>p;
if (p == 0) {
cout << 1 << '\n';
return 0;
}
int sol = 0;
for (int bit = getBiggestBit(p * 5); bit >= 0; -- bit) {
if (1LL * sol + (1LL << bit) <= p * 5 and zeros(sol + (1 << bit)) <= p) {
sol += (1 << bit);
}
}
cout << (sol - sol % 5) << '\n';
return 0;
}