比赛 26暑假集训模拟赛1 评测结果 WWWWWWWWWW
题目名称 最终得分 0
用户昵称 赵飞羽 运行时间 0.043 s
代码语言 C++ 内存使用 3.72 MiB
提交时间 2026-06-29 10:30:20
显示代码纯文本
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 510;
int n, p, fact[N], tot = 1;

int f(int x, int k) {
	if (x <= k) return fact[x];
	if (k == 1) return 1;
	return ((x - 1) * f(x - 1, k) % p + f(x - 1, k - 1) % p) % p;
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	freopen("great.in", "r", stdin);
	freopen("great.out", "w", stdout);
	cin >> n >> p;
	for (int i = 1; i <= n; i++) {
		tot = tot * i % p;
		fact[i] = tot;
	}
	cout << f(n, 3) % p;
	return 0;
}