1 条题解

  • 2
    @ 2023-7-25 18:06:13
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    using namespace std;
    struct _vlint {
    	static const int _size = 40000;
    	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(1);
        int n;
        scanf("%d", &n);
        for (int i = 1; i <= n; i++)
        	ans = ans * i;
    	ans.print();
    	return 0;
    }
    
    • 1

    信息

    ID
    424
    时间
    2000ms
    内存
    256MiB
    难度
    7
    标签
    (无)
    递交数
    110
    已通过
    22
    上传者