Precision four compression

Precision four compression 

Rationale: create an array of every deposit on the use of certain 4-digit calculation method to achieve large integer arithmetic;

 

In the packaging structure body;

At present, only precision + precision, high-precision single-precision *, max (high-precision, high-precision);

Code:

// precision four compression =========================================== ===== 
const  int M = 85 , MOD = 10000 ;
 struct the HP {
     int P [ 505 ], len;
    HP() {
        memset(p,0,sizeof(p));
        as = 0 ;
    } // initialize a variable precision 
    void put_out () { // output 
        the printf ( " % D " , P [len]);
         for ( int I = len . 1 ; I> 0 ; i-- ) {
             IF (P [I] == 0 ) {
                printf("0000");
                continue;
            }
            for(int k=10; k*p[i]<mod; k*=10)printf("0");
            printf("%d",p[i]);

        }
    }
} f[M][M],base[M],ans;
//高精+高精 O(len)
HP operator + (const HP &a,const HP &b) {
    HP c;
    c.len=max(a.len,b.len);
    int x=0;
    for(int i=1; i<=c.len; i++) {
        c.p[i]=a.p[i]+b.p[i]+x;
        x=c.p[i]/mod;
        c.p[i]%=mod;
    }
    if(x>0)c.p[++c.len]=x;
    return c;
}
@ High-precision single-precision * O (len) 
the HP operator * ( const the HP A &, const  int & B) {
    HP c;
    c.len=a.len;
    int x=0;
    for(int i=1; i<=c.len; i++) {
        c.p[i]=a.p[i]*b+x;
        x=c.p[i]/mod;
        c.p[i]%=mod;
    }
    while(x>0) {
        cp [ ++ c.len] = x% mod;
        x / = v;
    }
    return c;
}
//max 高精
HP max (const HP &a,const HP &b) {
    if(a.len>b.len)
        return a;
    if(a.len<b.len)
        return b;
    for(int i=a.len; i>0; i--) {
        if(a.p[i]>b.p[i])
            return a;
        if(a.p[i]<b.p[i])
            return b;
    }
    return a;
}
//================================================

 

Guess you like

Origin www.cnblogs.com/geraldg/p/12424114.html