Pagini recente » Cod sursa (job #48833) | Cod sursa (job #1485114) | Cod sursa (job #473820) | Cod sursa (job #1286078) | Cod sursa (job #806257)
Cod sursa(job #806257)
#include<fstream>
using namespace std;
ifstream f("date.in");
ofstream g("date.out");
int functia (int n)
{
int puterea=0,ck=5;
while (n/ck>=1)
{
puterea=n/ck+puterea;
ck=ck*5;
}
return puterea;
}
//int zero (int n)
//{
// int s=0,x;
// x=5;
// while (n>=1)
// {
// s=s+n/x;
// n=n/x;
//}
//return s;
//}
int main ()
{
int p,n,l1,l2,pp,z;
f>>p;
f>>n;
l1=1;
l2=1000000000;
pp=0;
while (l1<=l2&&pp==0)
{
n=(l1+l2)/2;
z=functia(n);
if (z==p)
{
pp=1;
n=n-n%5;
}
else
if (z<p)
l1=n+1;
else
l2=n-1;
}
if (pp==0)
g<<"-1";
else
if (pp==1)
g<<n;
if (p==0)
g<<1;
//g<<zero(n);
f.close ();
g.close ();
return 0;
}