Pagini recente » Cod sursa (job #2491388) | Cod sursa (job #1785160) | Cod sursa (job #955936) | Cod sursa (job #2255606) | Cod sursa (job #1399271)
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int src,Left,Right,Middle,nrCurZero;
int _NrZero(int x)
{
int s = 0;
while( x != 0 )
{
s += x / 5;
x /= 5;
}
return s;
}
int main()
{
fin>>src;
if( src == 0 )
{
fout<<1;
return 0;
}
Left = 1;
Right = 2000000000;
while( Left <= Right )
{
Middle = ( Left + Right ) / 2;
nrCurZero = _NrZero( Middle );
if( nrCurZero == src )
{
if( Middle % 5 == 0 )
{
fout<<Middle;
return 0;
}
Right = Middle - 1;
}
if( nrCurZero > src )
Right = Middle - 1;
else if( nrCurZero < src )
Left = Middle + 1;
}
fout<<-1;
return 0;
}