struct HighPrecision {
struct Number{
int num[20000];
int len;
}tem;
inline void Clear(Number &xxx) {
xxx.len = 0;
memset(xxx.num, 0, sizeof(xxx.num));
}
inline Number Change(long long a) {
Clear(tem);
int len = 0;
while (a != 0) {
len ++;
tem.num[len] = a %10;
a /= 10;
}
tem.len = len;
return tem;
}//低精转高精
inline Number Addition (Number &a, Number &b) {
int len = max(a.len, b.len);
Clear(tem);
for (int i = 1; i <= len; ++ i) {
tem.num[i] += (a.num[i] + b.num[i]);
if (tem.num[i] >= 10) {
tem.num[i + 1] += (tem.num[i] / 10);
tem.num[i] %= 10;
}
}
if (tem.num[len + 1] != 0) len ++;
tem.len = len;
return tem;
}//高精加
inline Number Product(Number &a, Number b) {
int len_a = a.len, len_b = b.len, len_c = 0;
Clear(tem);
for (int i = 1; i <= len_a + len_b; ++ i) {
tem.num[i] = 0;
}//记得初始化
for (int i = 1; i <= len_a; ++ i) {
for (int j = 1; j <= len_b; ++ j) {
tem.num[i + j - 1] += a.num[i] * b.num[j];
len_c = max(len_c, i + j - 1);
}
}
for (int i = 1; i <= len_c; ++ i) {
tem.num[i + 1] += (tem.num[i] / 10);
tem.num[i] %= 10;
if (i == len_c && tem.num[i + 1] != 0) {
len_c += 1;
}
}
while (tem.num[len_c] == 0) {
len_c --;
}
tem.len = len_c;
return tem;
}//高精乘法
inline void Print(Number &x) {
for (int i = x.len; i >= 1; -- i) {
cout << x.num[i];
}
cout << endl;
return;
}//输出
}Use;
标签:高精加,tem,int,Number,len,num,高精,高精乘
From: https://www.cnblogs.com/jueqingfeng/p/17478002.html