萌新求调qwq

P1009 [NOIP1998 普及组] 阶乘之和

喵仔牛奶 @ 2022-10-07 11:52:06

https://www.luogu.com.cn/record/89002249

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const ll mod = 1e17;
ll n, high, low, ht, lt;
int main(){
    cin >> n;
    for (int i = 1;i <= n; i ++) {
        ht = 0, lt = 1;  
        for (int j = 1; j <= i; j ++) {
            lt *= j, ht *= j;
            ht += lt / mod, lt %= mod;
        }
        high += ht, low += lt;
        high += low / mod, low %= mod;
    }
    if (high) cout << high;
    cout << low << '\n';
    return 0;
}

by AfterFullStop @ 2022-10-07 11:57:54

@喵仔牛奶 有没有一种可能,你的位数还是不够


by AfterFullStop @ 2022-10-07 11:58:30

50的阶乘


by yh2022mayu @ 2022-10-07 12:00:08

不用取模?


by AfterFullStop @ 2022-10-07 12:03:36

@mayu 要吧,毕竟lz的代码的意思是用两个ll一个存高位一个存低位


by yh2022mayu @ 2022-10-07 12:07:58

50阶乘>1e36了吧(否则还不如用int128


|