c++50分求助!!!

P1009 [NOIP1998 普及组] 阶乘之和

songchunxi @ 2023-03-13 18:37:59


#include <bits/stdc++.h>
using namespace std;

int mix(long long x){
    long long y=1;
    for(int i=2;i<=x;i++){
        y*=i;
    }
    return y;
}

int main(){
    long long n,i,s=1;
    cin>>n;
    for(i=2;i<=n;i++){
        s+=mix(i);
    }
    cout<<s<<endl;
    return 0;
}

by _colin1112_ @ 2023-03-13 18:42:15

@songchunxi

对于100%的数据,1≤n≤50。


by linmil @ 2023-03-13 19:13:08

要用高精度运算


by wssb1919810 @ 2023-03-22 21:35:48

50!=30414093201713378043612608166 064768844377641568960512000000000000

你悟了吗?(unsigned \ long \ long\text{最大值为}

18446744073709551615)

|