Problem1613end @ 2024-02-10 18:08:05
#include<bits/stdc++.h>
using namespace std;
int n,cap,jw,j[100000],a,zj[100000],zjw,sw;
int maxx(int qer,int per){
if(qer>per) return qer;
else return per;
}
int sr(int f){
int sw;
for(sw=jw;sw>=1;sw--){
j[sw]=j[sw]*f;
}
for(sw=1;sw<=jw;sw++){
if(j[sw]>=10){
j[sw+1]=j[sw+1]+j[sw]/10;
j[sw]=j[sw]%10;
}
}
if(j[jw+1]>0){
jw++;
if(j[jw+1]>=10){
j[jw+1]=j[jw+1]+j[jw]/10;
j[jw]=j[jw]%10;
jw++;
}
}
return 0;
}
int lj(){
for(cap=1;cap<=maxx(jw,zjw);cap++){
zj[cap]=zj[cap]+j[cap];
if(zj[cap]>=10){
zj[cap+1]++;
zj[cap]=zj[cap]%10;
}
}
zjw=maxx(zjw,jw);
if(zj[zjw+1]>0) zjw++;
return 0;
}
int main(){
cin>>n;
zjw=1;
zj[1]=1;
jw=1;
j[1]=1;
if(n==1){
cout<<1;
}
else{
for(a=2;a<=n;a++){
sr(a);
lj();
}
}
for(cap=zjw;cap>=1;cap--){
cout<<zj[cap];
}
return 0;
}
by HEROBRINEH @ 2024-02-10 18:20:49
同志,您字体改一下吧。
看一下俺的程序吧。
#include <bits/stdc++.h>
using namespace std;
namespace Integer {
const string symbol = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
template <size_t kMaxLength, int binary = 10, typename T = int> struct BigInt {
T n, a[kMaxLength];
bool f;
BigInt() { Init(); }
T &operator[](int i) { return a[i]; }
void Init() { // 初始化函数
n = f = 1;
fill(a, a + kMaxLength, 0);
}
/* 别管就是用 cin,cout 输入输出的东西用自己写的就行了 */
friend istream &operator>>(istream &tempStream, BigInt &a) {
string s;
tempStream >> s;
a.n = s.size();
if (s[0] == '-') {
a.f = 0;
a.n--, s.erase(0, 1);
}
for (int i = 0; i < a.n; i++) {
a[i] = (s[a.n - i - 1] >= 'A' && s[a.n - i - 1] <= 'Z'
? s[a.n - i - 1] - 'A' + 10
: s[a.n - i - 1] - '0');
}
return tempStream;
}
friend ostream &operator<<(ostream &tempStream, BigInt a) {
for (; a.n > 1 && !a[a.n - 1]; a.n--) {
}
if (!a.f) {
cout << '-';
}
for (int i = a.n - 1; i >= 0; i--) {
tempStream << symbol[a[i]];
}
return tempStream;
}
/* 运算符 */
void operator=(int x) {
Init();
if (!x) {
return;
}
if (x < 0) {
x = -x, f = 0;
}
n = 0;
while (x) {
a[n++] = x % binary;
x /= binary;
}
}
void operator=(string x) {
Init();
int st = 0;
if (x[0] == '-') {
f = 0, st++;
}
n = 0;
int len = x.size();
for (int i = st; i < len; i++) {
a[n++] = x[len - i - 1] - '0';
}
}
void operator=(BigInt x) {
Init();
n = x.n;
f = x.f;
for (int i = 0; i < n; i++) {
a[i] = x[i];
}
}
bool operator==(BigInt x) {
if (n != x.n) {
return 0;
}
for (int i = n - 1; i >= 0; i++) {
if (a[i] != x[i]) {
return 0;
}
}
return 1;
}
bool operator!=(BigInt x) { return !operator==(x); }
bool operator<(BigInt x) {
if (n == x.n) {
for (int i = n - 1; i >= 0; i--) {
if (a[i] != x[i]) {
return a[i] < x[i];
}
}
}
return n < x.n;
}
bool operator>(BigInt x) {
if (n == x.n) {
for (int i = n - 1; i >= 0; i--) {
if (a[i] != x[i]) {
return a[i] > x[i];
}
}
}
return n > x.n;
}
bool operator<=(BigInt x) { return !operator>(x); }
bool operator>=(BigInt x) { return !operator<(x); }
bool operator!() {
if (n != 1) {
return 0;
}
return !a[0];
}
bool operator==(int x) {
BigInt y;
y = x;
return operator==(y);
}
bool operator!=(int x) {
BigInt y;
y = x;
return operator!=(y);
}
bool operator<(int x) {
BigInt y;
y = x;
return operator<(y);
}
bool operator>(int x) {
BigInt y;
y = x;
return operator>(y);
}
bool operator<=(int x) {
BigInt y;
y = x;
return operator<=(y);
}
bool operator>=(int x) {
BigInt y;
y = x;
return operator>=(y);
}
/* 加法 */
BigInt operator+(BigInt x) {
BigInt y;
y.n = max(n, x.n);
for (int i = 0; i < y.n; i++) { // 加
y[i] = a[i] + x[i];
}
for (int i = 0; i < y.n - 1; i++) { // 进位
y[i + 1] += y[i] / 10;
y[i] %= 10;
}
for (; !y.a[y.n - 1] && y.n > 1; y.n--) { // 前导零
}
return y;
}
void operator+=(BigInt x) {
BigInt z = *this;
*this = z + x;
}
void operator+=(int x) {
BigInt z = *this;
*this = z + x;
}
BigInt operator+(int x) {
BigInt y;
y = x;
return operator+(y);
}
/* 乘法 */
BigInt operator*(BigInt x) {
BigInt y;
y.n = n + x.n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < x.n; j++) {
y[i + j] += a[i] * x[j]; // 乘
}
}
for (int i = 0; i < y.n - 1; i++) { // 进位
y[i + 1] += y[i] / binary, y[i] %= binary;
}
for (; !y.a[y.n - 1] && y.n > 1; y.n--) { // 前导零
}
return y;
}
void operator*=(BigInt x) {
BigInt z = *this;
*this = z * x;
}
void operator*=(int x) {
BigInt z = *this;
*this = z * x;
}
BigInt operator*(int x) {
BigInt ans;
ans.n = n + 2;
for (int i = 0; i < n; i++) {
ans[i] = a[i] * x;
}
for (int i = 0; i < n - 1; i++) {
ans[i + 1] += ans[i] / 10, ans[i] %= 10;
}
return ans;
}
};
};
using namespace Integer;
int n;
int main() {
cin >> n;
BigInt<100> ans;
ans = 0;
BigInt<100> sum;
sum = 1;
for (int i = 1; i <= n; i++) {
sum *= i;
ans += sum;
}
cout << ans;
return 0;
}