请大佬帮忙看看为什么精度还不够高,到20就出问题了

P1009 [NOIP1998 普及组] 阶乘之和

Mottled @ 2024-02-07 20:35:24

#include <iostream>
using namespace std;

int main()
{
    int n;
    unsigned long long s = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        unsigned long long a = 1;
        for (int j = 1; j <= i; j++)
        {
            a = a * j;

        }
        s += a;
    }
    cout << s;
    return 0;
}

by littlesnake @ 2024-02-07 20:39:18

@Mottled 高精度。


by ny_jerry2 @ 2024-02-07 20:39:26

20!爆long long了

用高精度


|