Pagini recente » tema | Cod sursa (job #442252) | Cod sursa (job #1811408) | Cod sursa (job #1365430) | Cod sursa (job #2735016)
#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 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;
}