Big number multiplication 大整数乘法

const int N = 1100 ;

struct BigNum ... {
intfront;
intdata[N+1];
}
;

BigNum
& Mulit(BigNumup,BigNumdown) ... {
inti,k,carry,v;
BigNumprod;
prod.front
=up.front+down.front-N+1;
for(i=prod.front;i<=N;i++)prod.data[i]=0;
for(i=N;i>=down.front;i--)...{
BigNumtmp;
carry
=0;
for(k=N;k>=up.front;k--)...{
v
=down.data[i]*up.data[k]+carry;
tmp.data[k]
=v%10;
carry
=v/10;
}

tmp.front
=up.front;
if(carry>0)tmp.data[--tmp.front]=carry;
carry
=0;
for(k=N;k>=tmp.front;k--)...{
v
=tmp.data[k]+prod.data[i+k-N]+carry;//wheni==N,ktok,theniisdecreased1eachstep.
prod.data[i+k-N]=v%10;
carry
=v/10;
}

while(carry>0)...{
v
=prod.data[i+k-N]+carry;
prod.data[i
+k-N]=v%10;
carry
=v/10;
k
--;
}

}

while(prod.data[prod.front]==0&&prod.front<N)prod.front++;
returnprod;
}

// 30'

你可能感兴趣的:(UP)