Pagini recente » Cod sursa (job #877928) | Cod sursa (job #588884) | Cod sursa (job #461539) | Cod sursa (job #1145752) | Cod sursa (job #2052166)
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int nrzero(int x)
{
int 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,a=nrzero(x),b,c=nrzero(y),gasit=0,mij;
f>>p;
if(p==0)
{
g<<1;
return 0;
}
while(x<=y && gasit==0)
{
mij=(x+y)/2;
b=nrzero(mij);
if(b==mij)
{
gasit=1;
}
if(b<p)
{
x=mij+1;
a=nrzero(x);
}
if(b>p)
{
y=mij-1;
c=nrzero(y);
}
}
if(gasit==1)
g<<mij-mij%5;
else g<<-1;
return 0;
}