巨佬求助C++#3#4WA

P1009 [NOIP1998 普及组] 阶乘之和

zhu_zhu_zhi_shen_zhu @ 2022-07-26 14:54:13

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b;
    cin >> a;
    for(int c=1;c<=a;c++)
    {
        long long d=1;
        for(int e=1;e<=c;e++)
        {
            d*=e;
        }
        b+=d;
    }
    cout << b;
}

by ShenRuochen @ 2022-07-26 14:59:40

您需要使用高精度。


by ShenRuochen @ 2022-07-26 14:59:58

@fyhluogu


by 晴空一鹤 @ 2022-07-26 15:00:27

This problem should use high Au.

@fyhluogu


by mzyc_yang2021 @ 2022-07-26 15:00:33

用高精。

#include<bits/stdc++.h>
using namespace std;
int n,a[101]={0},s[101]={0};
void change(int x)
{
    int g=0;
    for(int i=100;i>=0;i--)
    {
        a[i]=a[i]*x+g;
        g=a[i]/10;
        a[i]=a[i]%10;
    }
}
void qh()
{
    int g=0;
    for(int i=100;i>=0;i--)
    {
        s[i]=s[i]+a[i]+g;
        g=s[i]/10;
        s[i]=s[i]%10;
    }
}
void sc()
{
    int w;
    for(int i=0;i<=100;i++)
    {
        if(s[i]!=0)
        {
            w=i;
            break;
        }
    }
    for(int i=w;i<=100;i++)
       printf("%d",s[i]);
}
int main()
{
    scanf("%d",&n);
    s[100]=a[100]=1;
    for(int i=2;i<=n;i++)
    {
        change(i);
        qh();
    }
    sc();
    return 0;
}

by zhu_zhu_zhi_shen_zhu @ 2022-07-26 15:02:54

谢谢诸位大佬 qwp


|