0分求助!!!

P1009 [NOIP1998 普及组] 阶乘之和

chanthu2114 @ 2022-11-13 18:27:26

#include <stdio.h>
using namespace std;
int multi;
void factorial(int a)
{
    for (int i = a; i >= 1; i--)
        multi *= i;
} //阶乘函数,用来求a! 
int main()
{
    int n, ans = 0;
    scanf("%d", &n);
    for (int j = 1; j <= n; j++)
    {
        factorial(j);
        ans += multi;
        multi = 0; //按题意模拟 
    }
    printf("%d", ans); //输出 
    return 0;
}

by HarunluoON @ 2022-11-13 18:33:27

multi$ 初值应设为 $1

另:

如果希望通过本题,请继续学习第八章高精度的知识。


by chanthu2114 @ 2022-11-13 18:35:14

好吧谢谢!


by chanthu2114 @ 2022-11-13 18:39:02

用unsigned long long不行吗


|