2 条题解

  • -2
    @ 2023-7-25 18:07:31
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    using namespace std;
    struct _vlint {
    	static const int _size = 10010;
    	int len, num[_size];
    	_vlint(int a = 0) {
    		len = 1;
    		memset(num, 0, sizeof(num));
    		while (a) num[len] = a % 10, a /= 10, len++;
    		len--;
    	}
    	int &operator[](int a) {
    		return num[a];
    	}
    	void flat(int a) {
    		len = a;
    		for (int i = 1; i <= len; i++)
    			num[i + 1] += num[i] / 10, num[i] %= 10;
    		while (!num[len]) len--;
    	}
    	void print() {
    		for (int i = max(len, 1); i >= 1; i--)
    			printf("%d", num[i]);
    	}
    };
    _vlint operator+(_vlint a, _vlint b) {
    	_vlint c;
        int len = max(a.len, b.len);
        for (int i = 1; i <= len; i++) c[i] += a[i] + b[i];
        c.flat(len + 1);
        return c;
    }
    _vlint operator*(_vlint a, int b) {
    	_vlint c;
        int len = a.len;
        for (int i = 1; i <= len; i++) c[i] = a[i] * b;
        c.flat(len + 11);
        return c;
    }
    int main() {
        freopen("factorial.in", "r", stdin);
        freopen("factorial.out", "w", stdout);
        _vlint ans(0), fac(1);
        int n;
        scanf("%d", &n);
        for (int i = 1; i <= n; i++) {
        	fac = fac * i;
        	ans = ans + fac;
    	}
    	ans.print();
    	return 0;
    }
    

    信息

    ID
    429
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    (无)
    递交数
    130
    已通过
    23
    上传者