Pagini recente » Cod sursa (job #2063077) | Cod sursa (job #1051481) | Cod sursa (job #2622865) | Cod sursa (job #258289) | Cod sursa (job #2735024)
#include <iostream>
#include <fstream>
using namespace std;
/*int nrZerouriFact(int p)
{
int nr = 0, pow = 5;
while(pow <= p)
{
for(int i = pow; i <= p; i+=pow)
{
nr++;
}
pow*=5;
}
return nr;
}*/
int nrZerouriFact(int p)
{
int nr = 0;
for(int i = 5; p / i >= 1; i*=5)
{
nr += p / i;
}
return nr;
}
int main()
{
ifstream fin("fact.in");
ofstream fout("fact.out");
int p, n, a = 0, b, mij;
fin>>p;
b = p * 5;
bool gasit = false;
while(!gasit && a <= b)
{
mij = (a + b) / 2;
int nrZeroMij = nrZerouriFact(mij);
if(nrZeroMij == p)
{
gasit = true;
n = mij;
}
else if(nrZeroMij > p)
{
b = mij - 1;
}
else
{
a = mij + 1;
}
}
fout<<(gasit?(n/5)*5:-1);
return 0;
}