Pagini recente » Cod sursa (job #811424) | Cod sursa (job #1803785) | tema | Statistici Balosu Mihai Costinel (MIhaiBalosu) | Cod sursa (job #941055)
Cod sursa(job #941055)
//problema facauta la plictiseala
//n-aveam altceva mai bun de facut
#include<fstream>
#include<utility>
using namespace std;
int p;
int Answer;
ifstream f("fact.in");
ofstream g("fact.out");
int numb_power5( int n)
{
int cnt(0);
int x(5);
while( x <= n )
{
cnt+=n/x;
x*=5;
}
return cnt;
}
int binary_search ( int left , int right )
{
if(left>right)
return 0;
int mid=(left+right)>>1;
int number=numb_power5(mid);
if(number == p )
return mid;
else
if( number<p)
binary_search(mid-1,right);
else
binary_search(left,mid-1);
}
int main ( void )
{
f>>p;
if( p == 0)
g<<1;
else
{
Answer=binary_search(1,2000000000);
if( Answer == 0 )
g<<-1;
else
{
while( Answer % 5 )
--Answer;
g<<Answer;
}
}
f.close();
g.close();
return 0;
}