Cod sursa(job #12956)

Utilizator za_wolf1sdgsdgasdgasdfasdfasdf za_wolf1 Data 5 februarie 2007 12:49:12
Problema Factorial Scor 55
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include<fstream.h>
#include<math.h>
long long max,n,p,a,i,s,x[20],y[20],k;
/*int kkt(long long a)
{
long long  i,s;
s=0;
i=5;
while (a/i>=1)
{
s+=a/i;
i=i*5;
}
if (s==n) return s; else return 0;
} */
int main()
{
ifstream f("fact.in");
ofstream g("fact.out");
f>>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;

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

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


/*i=0;
for (i=y[k];i<=y[k+1];i+=5)
{
a=0;
a=kkt(i);
if (a) {max=i;i=y[k+1];}
} */
s=0;
while (n>=1)
{
for (i=1;i<=13;i++)
if (n<=x[i]) {k=i-1; i=13;}
s+=n/x[k]*y[k];
n=n%x[k];
}
if (s==0) g<<"-1"<<"\n"; else g<<s<<"\n";
f.close();
g.close();
return 0;
}