题目P1009,返回结果:#1AC #2AC #3WA #4WA,

P1009 [NOIP1998 普及组] 阶乘之和

Aiden_H @ 2023-09-22 21:15:37

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
    int n;
    cin >> n;
    unsigned long long sum = 0;
    unsigned long long product;
    for (unsigned long long j = 1; j <= n; j++)
    {
        product = j;
        for (unsigned long long i = j - 1; i > 0; i--)
        {
            product *= i;
        }
        sum += product;
    }
    cout << sum << endl;
    return 0;
}

by One_JuRuo @ 2023-09-22 21:17:32

@Aiden_H

unsigned long long 会爆掉吧,要用高精度


by Sreffial @ 2023-09-22 21:18:56

看算法标签,高精度@Aiden_H


by Aiden_H @ 2023-09-22 21:26:42

@One_JuRuo 能教下我高精度怎么用吗


by yyrwlj @ 2023-09-22 21:29:19

@Aiden_H STFW


by One_JuRuo @ 2023-09-22 21:33:57

@Aiden_H 用数组存数字,一位一位的存,然后计算和竖式差不多,一位一位算。

建议看题解或者OIWIKI


by Aiden_H @ 2023-09-23 13:59:14

@One_JuRuo 谢谢


|