wangshengchen @ 2024-09-08 10:19:43
#include <iostream>
using namespace std;
int main()
{
int N,A=1,B=0;
cin>>N;
for(int i=1;i<=N;i++)
{
A=1;
for(int m=1;m<=i;m++)
{
A*=m;
}
B+=A;
}
cout<<B;
return 0;
}
by yxszcxl @ 2024-09-17 17:48:32
#include <bits/stdc++.h>
using namespace std;
#define maxn 100
struct Bigint {
int len, a[maxn];
Bigint(int x = 0) {
memset(a, 0, sizeof(a));
for (len = 1; x; len++) {
a[len] = x % 10, x /= 10;
}
len--;
}
int &operator[](int i) {
return a[i];
}
void flatten(int L) {
len = L;
for (int i = 1; i < len; i++) {
a[i + 1] += a[i] / 10, a[i] %= 10;
}
for (; !a[len];) {
len--;
}
}
void print() {
for (int i = max(len, 1); i >= 1; i--) {
printf("%d", a[i]);
}
}
};
Bigint operator+(Bigint a, Bigint b) {
Bigint c;
int len = max(a.len, b.len);
for (int i = 1; i <= len; i++) {
c[i] += a[i] + b[i];
}
c.flatten(len + 1); //public void Bigint::flatten(int L)
return c;
}
Bigint operator*(Bigint a, int b) {
Bigint c;
int len = a.len;
for (int i = 1; i <= len; i++) {
c[i] = a[i] * b;
}
c.flatten(len + 11);
return c;
}
int main() {
Bigint ans(0), fac(1);
int m;
cin >> m;
for (int i = 1; i <= m; i++) {
fac = fac * i;
ans = ans + fac;
}
ans.print();
return 0;
}
by Even_lwx @ 2024-09-21 10:03:41
这题用long long这些都不够
通常使用一维数组来模拟大整数的存储,数组的每个元素存储大整数的一位数字。例如,数组 int num[100] 可以用来存储一个最多 100 位的大整数,num[0] 存储个位数字,num[1] 存储十位数字,以此类推。
计算要模拟手工的计算(目前我是这样想的)