Pagini recente » Cod sursa (job #1250382) | Cod sursa (job #2708591) | Cod sursa (job #161313) | Cod sursa (job #364467) | Cod sursa (job #175209)
Cod sursa(job #175209)
#include<fstream.h>
#include<iostream.h>
#include<values.h>
#include<math.h>
int main()
{
long p,min=0,total,x,i,max,y[12],j;
fstream f,g;
f.open("fact.in",ios::in);
f>>p;
f.close();
max=500000000;
x=250000000;
min=0;
for(i=1;i<=11;i++)
y[i]=pow(5,i);
g.open("fact.out",ios::out);
if(p==0)
g<<1;
else
{
if(p%6==5||p%31==30||p%156==155||p%781==780)
g<<-1;
else
for(i=1;i<=28;i++)
{
total=0;
for(j=1;j<=11;j++)
{
total=x/y[j]+total;
if(total>p)
break;
}
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;
}
}
}
g.close();
return 0;
}