Pagini recente » Cod sursa (job #346616) | Profil mihnea.anghel | Cod sursa (job #3003322) | Cod sursa (job #1483070) | Cod sursa (job #76337)
Cod sursa(job #76337)
#include <fstream.h>
using namespace std;
ifstream input;
ofstream output;
int p;
int citire ()
{
input.open("fact.in",ifstream::in);
output.open("fact.out",'w');
input >> p;
input.close();
return 0;
}
int verif(int x)
{
int rez=0;
while (x >= 5)
{
rez = rez + x / 5;
x = x / 5;
}
return rez;
}
int cautarebin(int a,int b)
{
int x,val;
bool gasit=false;
while ((a < b) && (a != b))
{
x=(a+b)/2;
x = x-(x%5);
val=verif(x);
if (val == p)
{
output << x;
gasit=true;
break;
} else
if (val < p)
{
a=(a+b)/2;
} else
{
b=(a+b)/2;
}
}
if (! gasit) output << "-1";
return 0;
}
int main(int argc, char* argv[])
{
citire();
if (p==0) output << "1";
else cautarebin(0,100);
output.close();
return 0;
}
//---------------------------------------------------------------------------