Pagini recente » Cod sursa (job #2511684) | Cod sursa (job #2292098) | Cod sursa (job #193995) | Cod sursa (job #1230394) | Cod sursa (job #2218340)
#include <bits/stdc++.h>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long P;
long long st, dr, mid;
int i;
bool ok=false;
long long zero (long long x)
{
long long putere=5;
long long cnt=0;
while(putere<=x) {
cnt+=x/putere;
putere*=5;
}
return cnt;
}
int main()
{
f>>P;
st=1;
dr=5*P;
long long step=1;
while(step<dr)
step<<=1;
for(i=1; step; step>>=1) {
if(i+step<=dr && zero(i+step)<=P)
i+=step;
}
while(zero(i)==P && i>=1) {
i--;
ok=true;
}
i++;
if(ok==true)
g<<i<<'\n';
else g<<-1;
return 0;
}