社区讨论

0分求调

P1009[NOIP 1998 普及组] 阶乘之和参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mjycwlr4
此快照首次捕获于
2026/01/03 21:46
2 个月前
此快照最后确认于
2026/01/07 19:10
上个月
查看原帖
CPP
#include <iostream>
#include <algorithm>
#include <cstring>
#define Please return
#define AC 0
using namespace std;
const int MAXN = 1e6 + 5;
int n;

struct Big {
	int a[MAXN] = {};
	Big() {
		a[0] = 1;
	}
	Big(string s) {
		a[0] = s.size();
		for (int i = 0; i < s.size(); i++) {
			a[a[0] - i] = s[i] - '0';
		}
	}
	void read() {
		string s;
		cin >> s;
		a[0] = s.size();
		for (int i = 0; i < s.size(); i++) {
			a[a[0] - i] = s[i] - '0';
		}
	}
	Big &operator = (const Big &o) {
		if (this != &o) {
            for (int i = 0; i <= o.a[0]; i++) {
                a[i] = o.a[i];
            }
        }
        return *this;
	}
	Big &operator += (const Big &o) {
		int len = max(a[0], o.a[0]);
		int c = 0;
		for (int i = 1; i <= len; i++) {
			int now = a[i] + o.a[i] + c;
			a[i] = now % 10;
			c = now / 10;
		}
		if (c > 0) {
			len++;
			a[len] = c;
		}
		while (a[len] == 0 && len > 1) {
			len--;
		}
		a[0] = len;
		return *this;
	}
	Big &operator *= (const int &k) {
		int g = 0;
		int len = a[0];
		for (int i = 1; i <= len; i++) {
			int now = a[i] * k + g;
			a[i] = now % 10;
			g = now / 10;
		}
		while (g) {
			a[++len] = g % 10;
			g /= 10;
		}
		if (a[len + 1] > 0) {
			len++;
		}
		while (a[len] == 0 && len > 1) {
			len--;
		}
		a[0] = len;
		return *this;
	}
	void print() {
		for (int i = a[0]; i >= 1; i--) {
			cout << a[i];
		}
		cout << endl;
	}
} now("1"), ans("0");

int main(){
	cin >> n;
	for (int i = 1; i <= n; i++) {
		now.a[0] = now.a[1] = 1;
		for (int j = 1; j <= i; j++) {
			now *= j;
		}
		ans += now;
	}
	ans.print();
	Please AC;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...