主要思想使用数组(理论上链表也可以)并根据加法法则来写出代码·来承担超大数(好像木桶)
#include<iostream>
#include<cmath>
using namespace std;
int a2[1000];
int b3[1000];
int main(void) {
int a = 2, b = 3;
int sum[1000];
for (int i = 0; i < 1000; i++) {
sum[i] = 0;
a2[i] = 0;
b3[i] = 0;
}
a2[0] = 2;//2的一次方
b3[0] = 3;//3的一次方
进行初始化数组
for (int i = 0; i < 2022; i++)
{
for (int j = 0; j < 1000; j++) {
a2[j] *= 2;
}
for (int j = 0; j < 1000; j++) {
if (a2[j] >= 10) {
a2[j] = a2[j] - 10;
a2[j + 1]++;
}
}
}
求2^2023并储存到数组a2中(储存顺序为倒序储存)
储存原理如下:
for (int i = 0; i < 2022; i++)
{
for (int j = 0; j < 1000; j++) {
b3[j] *= 3;
}
for (int j = 0; j < 1000; j++) {
if (b3[j] >= 10) {
if (b3[j] >= 20) {
b3[j] = b3[j] - 10;
b3[j + 1]++;
}
b3[j] = b3[j] - 10;
b3[j + 1]++;
}
}
}
求3^2023并储存到b3数组中(储存序列为倒序储存)
for (int i = 0; i < 1000; i++) {
sum[i] = a2[i] + b3[i];
}
for (int j = 0; j < 1000; j++) {
if (sum[j] >= 10) {
sum[j] = sum[j] - 10;
sum[j + 1]++;
}
}cout << endl;
for (int i = 965; i > 0; i--) {
cout << sum[i]<<endl;
}
求和并输出(倒序输出)
标签:10,int,2023,++,a2,b3,1000 From: https://www.cnblogs.com/yiyulhb/p/17531943.html