Pagini recente » Cod sursa (job #1692158) | Cod sursa (job #189412) | Istoria paginii runda/proba123451/clasament | Cod sursa (job #1465712) | Cod sursa (job #2734992)
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
long long nrZerouriFact(long long p)
{
long long nr = 0;
for(long long i = 5; i <= p; i+=5)
{
long long n = 0, j = i;
while(j%5==0)
{
j/=5;
n++;
}
nr+=n;
}
return nr;
}
int main()
{
ifstream fin("fact.in");
ofstream fout("fact.out");
long long p, n, a = 0, b, mij;
fin>>p;
b = p * 5;
bool gasit = false;
while(!gasit && a <= b)
{
mij = (a + b) / 2;
long long 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;
}