GDCPC2021 F - Fake Math Problem(简单数学)

题目

source

题解

由于\(998241383=673 \times 937 \times 1583\),故最多枚举1583项后剩余的f值为0,直接暴力算,时间复杂度O(1583n)
不能用逆元!本来想分解质因数后算完用CRT合并,但是忘记了最多1583项后结果出现0,导致逆元出错。调了巨久。阶乘需要注意出现0。

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int M = 998241383;
typedef long long ll;
#define endl '\n'
typedef long long ll;

ll arr[N];
ll ans;
 

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		for(int i = 0; i <= n; i++) {
			cin >> arr[i];
		}
		ans = 0;
		for(int j = 0; j <= n; j++) {
			ll tmp = 1;
			for(int k = 0; tmp && k <= arr[j]; k++) {
				ans += tmp;
				ans %= M;
				tmp = tmp * (j - k) % M;
			}
		}
		cout << ans << endl;
	}
}
posted @ 2021-07-08 00:25  limil  阅读(150)  评论(0编辑  收藏  举报