Pagini recente » Cod sursa (job #1572011) | Cod sursa (job #2765712) | Cod sursa (job #2564874) | Cod sursa (job #1486288) | Cod sursa (job #1024719)
#include<iostream>
#include<stdio.h>
#define Nmax 100000000
using namespace std;
void search_number(int low, int high, int nr)
{
int nr5, putere5 = 5;
int x = ( low + high ) / 2;
nr5 = x / 5;
while(true)
{
putere5 *= 5;
if(x / putere5 == 0)
break;
nr5 = nr5 + ( x / putere5 );
}
if(nr5 == nr)
{
while(x % 5 != 0)
x--;
cout << x << endl;
}
else if(nr5 < nr)
search_number((low+high)/2, high, nr);
else
search_number(low, (low+high)/2, nr);
}
int main()
{
int P;
int upper_bound = 100000000;
int lower_bound = 0;
freopen("fact.in","r", stdin);
freopen("fact.out", "w", stdout);
cin >> P;
if(P == 0)
{
cout << '1' << endl;
return 0;
}
search_number(lower_bound, upper_bound, P);
return 0;
}