[tem]高精度2
从1开始
const int N=85; const int B=1e4,L=100; struct big{ int size,d[L]; big(int a=1):size(a){memset(d,0,sizeof(int)*L);} }; void jia(big &a,big &b){ int g=0,i; for(i=1;;i++){ if(g==0&&i>a.size&&i>b.size) break; int tmp=g; if(i<=a.size) tmp+=a.d[i]; if(i<=b.size) tmp+=b.d[i]; a.d[i]=tmp%B; g=tmp/B; } a.size=i-1; } void cheng(big &a,big &b,big &c){ for(int i=1;i<=a.size;i++){ int g=0; for(int j=1;j<=b.size;j++){ c.d[i+j-1]+=a.d[i]*b.d[j]+g; g=c.d[i+j-1]/B; c.d[i+j-1]%=B; } c.d[i+b.size]=g; } c.size=a.size+b.size; while(c.d[c.size]==0&&c.size>1) c.size--; } void chengInt(big &a,int k){ int g=0,i; for(i=1;i<=a.size;i++){ int tmp=a.d[i]*k; a.d[i]=(tmp+g)%B; g=(tmp+g)/B; } while(g){ a.d[++a.size]=g%B; g/=B; } } void copy(big &t,big &s){ t.size=s.size; for(int i=1;i<=s.size;i++) t.d[i]=s.d[i]; } big max(big &a,big &b){ if(a.size>b.size) return a; if(a.size<b.size) return b; for(int i=a.size;i>=1;i--){ if(a.d[i]>b.d[i]) return a; if(a.d[i]<b.d[i]) return b; } return a; } void print(big &a){ for(int i=a.size;i>=1;i--){ if(i==a.size); else if(a.d[i]<10) cout<<"0000"; else if(a.d[i]<100) cout<<"00"; else if(a.d[i]<1000) cout<<"0"; cout<<a.d[i]; } cout<<"\n"; }
Copyright:http://www.cnblogs.com/candy99/