Pagini recente » Cod sursa (job #1654429) | Cod sursa (job #1270846) | Cod sursa (job #946809) | Cod sursa (job #283920) | Cod sursa (job #1024746)
#include<iostream>
#include<stdio.h>
#define Nmax 100000000
using namespace std;
int P;
void search_number(int low, int high)
{
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 == P)
{
int q = x / 5;
x = q * 5;
cout << x << endl;
}
else if(nr5 < P)
search_number((low+high)/2, high);
else
search_number(low, (low+high)/2);
}
int main()
{
int upper_bound = 100000000;
int lower_bound = 0;
int sol;
freopen("fact.in","r", stdin);
freopen("fact.out", "w", stdout);
cin >> P;
if(P == 0)
{
cout << '1' << endl;
return 0;
}
while(true)
{
int nr5, putere5 = 5;
int x = ( lower_bound + upper_bound ) / 2;
nr5 = x / 5;
while(true)
{
putere5 *= 5;
if(x / putere5 == 0)
break;
nr5 = nr5 + ( x / putere5 );
}
if(nr5 == P)
{
sol = x;
if(sol % 5 == 0)
break;
}
if(nr5 < P)
{
lower_bound = (lower_bound + upper_bound)/2 + 1;
}
else
{
upper_bound = (lower_bound + upper_bound)/2 - 1;
}
}
cout << sol << endl;
return 0;
}