Pagini recente » Cod sursa (job #1046138) | Cod sursa (job #1929406) | Cod sursa (job #76339)
Cod sursa(job #76339)
#include <fstream.h>
using namespace std;
ifstream input("fact.in");
ofstream output("fact.out");
int p;
int citire ()
{
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;
}
//---------------------------------------------------------------------------