Pagini recente » Utilizatori inregistrati la Infoarena Monthly 2012 - Runda 6 | Cod sursa (job #2104338) | Cod sursa (job #1735395) | Cod sursa (job #300412) | Cod sursa (job #175190)
Cod sursa(job #175190)
#include<fstream.h>
#include<iostream.h>
#include<values.h>
#include<math.h>
int main()
{
long p,min=0,total,x,i,max;
fstream f,g;
f.open("fact.in",ios::in);
f>>p;
f.close();
max=500000000;
x=250000000;
min=0;
g.open("fact.out",ios::out);
for(i=1;i<=30;i++)
{
total=0;
for(i=1;i<=12;i++)
total=x/pow(5,i)+total;
if(total==p)
{
x=x-x%5;
g<<x;
break;
}
else
if(total<p)
{
min=x;
x=(min+max)/2;
}
else
{
max=x;
x=(min+max)/2;
}
}
if(i==30)
g<<-1;
g.close();
return 0;
}