Pagini recente » Monitorul de evaluare | Cod sursa (job #176915) | Cod sursa (job #2182586) | Cod sursa (job #124130) | Cod sursa (job #849641)
Cod sursa(job #849641)
#include<fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int fct (int x)
{
int putere=0,k=5;
while (x/k>=1)
{
putere=x/k+putere;
k=k*5;
}
return putere;
}
int main ()
{
int p,n,x1,x2,pp,y;
f>>p;
f>>n;
x1=1;
x2=1000000000;
pp=0;
while (x1<=x2&&pp==0)
{
n=(x1+x2)/2;
y=fct(n);
if (y==p)
{
pp=1;
n=n-n%5;
}
else
if (y<p)
x1=n+1;
else
x2=n-1;
}
if (pp==0)
g<<"-1"<<"\n";
else
if (p==0)
g<<1<<"\n";
else
if (pp==1)
g<<n<<"\n";
}