Pagini recente » Rating Ionescu Alexandru (ialexandru93) | Cod sursa (job #2725488) | Cod sursa (job #1771512) | Cod sursa (job #1851381) | Cod sursa (job #2735002)
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
long long nrZerouriFact(long long p)
{
long long nr = 0;
for(long long i = 1; i <= p/5; i+=1)
{
long long n = 0, j = i;
while(j%5==0)
{
j/=5;
n++;
}
nr+=n;
}
return nr+p/5;
}
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;
}