Pagini recente » Cod sursa (job #2131750) | Cod sursa (job #1436446) | Cod sursa (job #2857089) | Cod sursa (job #1522818) | Cod sursa (job #2052291)
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int nrzero(int x)
{
long long s=0;
long long p=5;
while(p<=x)
{
s=s+x/p;
p=p*5;
}
return s;
}
int main()
{ int p,x=5,y=2000000000,mij,a,b,gasit=0;
in>>p;
if(p==0)
{
out<<1;
return 0;
}
while(x<=y&&gasit==0)
{
a=nrzero(x);
b=nrzero(y);
mij=(x+y)/2;
if(b==p)
gasit=1;
if(b<p)
x=mij+1;
else y=mij-1;
}
if(gasit==1) out<<mij-mij%5;
if(gasit==0) out<<-1;
return 0;
}