Pagini recente » Cod sursa (job #1770757) | Cod sursa (job #217941) | Cod sursa (job #1776275) | Cod sursa (job #220366) | Cod sursa (job #445977)
Cod sursa(job #445977)
#include<fstream.h>
#define max 400000015
int p;
int zero(int n)
{
int k=0;
while(n)
{
k=k+n/5;
n=n/5;
}
return k;
}
int main()
{
ifstream f("fact.in");ofstream g("fact.out");
int st=1,dr=max,z,k=0;
f>>p;
if(p==0)g<<1;
else
{
while(st<=dr && k==0)
{
int m=st+(dr-st)/2;
z=zero(m);
if(z==p)k=m;
else if(z<p)st=m+1;
else dr=m-1;
}
if(k)g<<k-k%5;
else g<<-1;
}
f.close();g.close();
return 0;
}