achjuncool @ 2022-07-04 18:07:55
代码如下:
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
struct bi{
public:
int num[1000], len = 0;
bi(string i = "0"){
memset(num, 0, sizeof(num));
for(int j = i.length() - 1; j >= 0; j--){
num[i.length() - j] = i[j] - '0';
len++;
}
}
int leng(){
return len;
}
void print(){
for(int i = len; i >= 1; i--){
cout << num[i];
}
}
bi operator +(bi tee){
int x = 0;
bi t;
int tlen = 0;
for(int i = 1; i <= max(this->leng(), tee.leng()); i++){
t.num[i] += x;
t.num[i] += this->num[i] + tee.num[i];
x = t.num[i] / 10;
t.num[i] %= 10;
tlen++;
}
if(x > 0){
tlen++;
t.num[tlen] = x;
}
t.len = tlen;
return t;
}
bi operator *(int tee){
int x = 0;
bi t;
int tlen = 0;
for(int i = 1; i <= this->leng(); i++){
t.num[i] += this->num[i] * tee;
t.num[i] += x;
x = t.num[i] / 10;
t.num[i] %= 10;
tlen++;
}
if(x > 0){
tlen++;
t.num[tlen] = x;
}
t.len = tlen;
return t;
}
};
int main(){
int n;
cin >> n;
bi ans, cur("1");
for(int i = 1; i <= n; i++){
cur = (cur * i);
ans = (ans + cur);
}
ans.print();
cout << endl;
return 0;
}
by achjuncool @ 2022-07-04 18:20:28
好的过了qwq