Cod sursa(job #12973)

Utilizator za_wolf1sdgsdgasdgasdfasdfasdf za_wolf1 Data 5 februarie 2007 13:00:57
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include<fstream.h>
#include<math.h>
unsigned long 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;

y[0]=1;
for (i=1;i<=13;i++)
y[i]=pow(5,i);




s=0;
while (n>=1)
{
for (i=1;i<=13;i++)
if (n<=x[i]) {k=i-1; i=13;}
if (k!=0)

{
s+=n/x[k]*y[k];
n=n%x[k];
}

else
{
s+=n*y[k];
n=0;
}
}
if (m==0) g<<"1"<<"\n"; else
if (s==0) g<<"-1"<<"\n"; else g<<s<<"\n";
f.close();
g.close();
return 0;
}