Pagini recente » Cod sursa (job #2275854) | Cod sursa (job #12999)
Cod sursa(job #12999)
#include<fstream.h>
#include<math.h>
unsigned long s2,max,n,m,p,a,i,s,x[20],y[20],k;
int main()
{
ifstream f("fact.in");
ofstream g("fact.out");
f>>n;
m=n;
x[1]=1;
x[2]=6;
x[3]=31;
x[4]=156;
x[5]=781;
x[6]=3906;
x[7]=19531;
x[8]=97656;
x[9]=488281;
x[10]=2441406;
x[11]=12207031;
x[12]=61035156;
x[13]=305175781;
x[14]=1000000000;
y[0]=1;
for (i=1;i<=13;i++)
y[i]=pow(5,i);
s=0;
while (n>=1)
{
for (i=1;i<=14;i++)
if (n<x[i]) {k=i-1; i=14;}
if (k!=0)
{
s+=n/x[k]*y[k];
n=n%x[k];
}
else
n=0;
}
n=m+1;
s2=0;
while (n>=1)
{
for (i=1;i<=14;i++)
if (n<x[i]) {k=i-1; i=14;}
if (k!=0)
{
s2+=n/x[k]*y[k];
n=n%x[k];
}
else
n=0;
}
if (m==0) g<<"1"<<"\n"; else
if (s==s2) g<<"-1"<<"\n"; else g<<s<<"\n";
f.close();
g.close();
return 0;
}