#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<climits>
#include<map>
#include<set>
using namespace std;
#define MAXM 205
#define INF 0x7f7f7f7f
const int MAXN = 2000;
struct BIGNUM{
int len, s[MAXN];
BIGNUM(){ len = 1 ; memset( s , 0 , sizeof(s)); }
void get(){
char num[MAXN];
cin >> num;
int n = strlen(num);
for(len = 0; len < n; len++)
s[len] = num[len] - '0';
return ;
}
void print(){
for(len --; len >= 0; len--)
printf("%d", s[len]);
return ;
}
BIGNUM operator = ( const char * num ){
len = strlen(num);
for( int i = 0 ; i < len ; ++ i ) s[i] = num[ len - i - 1 ] - '0';
return * this;
}
BIGNUM operator = ( const int num ){
char a[MAXN];
sprintf( a , "%d" , num );
* this = a;
return * this;
}
BIGNUM( const int num ){ * this = num; }
BIGNUM( const char * num ){ * this = num; }
BIGNUM operator + ( const BIGNUM & a ) const{
BIGNUM c;
c.len = max( len , a.len ) + 1;
for( int i = 0 , x = 0; i <c.len ; ++ i ){
c.s[i] = s[i] + a.s[i] + x;
x = c.s[i] / 10;
c.s[i] = c.s[i] % 10;
}
if( c.s[ c.len - 1 ] == 0 ) c.len --;
return c;
}
BIGNUM operator += ( const BIGNUM & a ){
* this = *this + a;
return * this;
}
BIGNUM operator * ( const BIGNUM & x ){
BIGNUM c;
c.len = len + x.len;
for( int i = 0 ; i < len ; ++ i )
for( int j = 0 ; j < x.len ; ++ j){
c.s[ i + j ] += s[i] * x.s[j];
c.s[ i + j + 1 ] += c.s[ i + j ] / 10;
c.s[ i + j ] %= 10;
}
if( c.s[ c.len - 1 ] == 0 ) c.len --;
return c;
}
BIGNUM operator *= ( const BIGNUM & a ){
* this = * this * a;
return * this;
}
bool operator < ( const BIGNUM & x ) const {
if( len != x.len ) return len < x.len;
for( int i = len - 1 ; i >= 0 ; -- i ){
if( s[i] != x.s[i] )
return s[i] < x.s[i];
}
return 0;
}
bool operator > ( const BIGNUM & x ) const { return x < * this; }
bool operator <= ( const BIGNUM & x ) const { return !( x < *this ); }
bool operator >= ( const BIGNUM & x ) const { return !( x > * this ); }
bool operator == ( const BIGNUM & x ) const { return !( x < * this || * this < x ); }
bool operator != ( const BIGNUM & x ) const { return x < * this || * this < x; }
}a, b, f = INT_MAX, t;
ostream & operator << ( ostream & out , const BIGNUM & x ){
for( int i = x.len - 1 ; i >= 0 ; -- i )
cout << x.s[i];
return out;
}
istream & operator >> ( istream & in , BIGNUM & x ){
char num[MAXN];
in >> num;
x = num;
return in;
}
int main(){
return 0;
}
高精度板( 无除法、减法 )
最新推荐文章于 2025-03-17 21:54:28 发布
本文介绍了一个自定义的大数类BIGNUM,实现了大数的基本运算,包括加法、乘法等,并提供了比较操作符。该类使用C++实现,能够处理超过标准整型范围的大数。

871

被折叠的 条评论
为什么被折叠?



