Pagini recente » Cod sursa (job #88515) | Cod sursa (job #2217098) | Cod sursa (job #2971246) | Cod sursa (job #2777307) | Cod sursa (job #1024766)
#include<iostream>
#include<stdio.h>
#define Nmax 100000000
using namespace std;
int P;
int main()
{
int upper_bound = 100000000;
int lower_bound = 0;
int sol = 100000001;
freopen("fact.in","r", stdin);
freopen("fact.out", "w", stdout);
cin >> P;
if(P == 0)
{
cout << '1' << endl;
return 0;
}
while(lower_bound < upper_bound)
{
int nr5 = 0, putere5 = 5;
int mid = ( lower_bound + upper_bound ) / 2;
for(int putere5 = 5; mid / putere5; putere5 *= 5)
nr5 += mid / putere5;
if(nr5 == P)
{
if(mid < sol)
sol = mid;
while(sol % 5 != 0)
sol--;
}
if(nr5 < P)
{
lower_bound = mid + 1;
}
else
{
upper_bound = mid - 1;
}
}
cout << sol << endl;
return 0;
}