首页 > 其他 > 详细

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

时间:2021-07-08 10:23:21      阅读:55      评论:0      收藏:0      [点我收藏+]

题目

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;
	}
}

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

原文:https://www.cnblogs.com/limil/p/14984308.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!