求助大佬们,为什么超时了呀?o(╥﹏╥)o

P1009 [NOIP1998 普及组] 阶乘之和

Lindafish @ 2024-01-20 22:19:42

#include <stdio.h>

int main ( )
{
    int n;
    scanf("%d",&n);
    int i=1,sum=0;
    for (i=1;i<=n;i++){
        int jc=1;
        while(i!=0){
            jc=jc*i;
            i--;
        sum+=jc;
        }
    }
    printf("%d",sum);

    return 0;
}

by CQBZ_ZJYjoe @ 2024-01-20 22:22:47

第一,阶乘只需要从1乘到 N

第二,你需要写高精度,建议多学一学


by CQBZ_ZJYjoe @ 2024-01-20 22:23:17

@Lindafish


by Lindafish @ 2024-01-21 00:08:40

@CQYC_ZJYjoe 谢谢大佬,我再学习一下


by hayhey @ 2024-01-31 22:51:48

long long int a=1; long long int S=0; printf("%lld",S); 呜呜 为啥我的也才50


|