Hello 2020 C. New Year and Permutation 组合数学

C. New Year and Permutation

在这里插入图片描述

input

2020 437122297

output

265955509

code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int INF = 0x3f3f3f3f;
const int N = 3e5+10;
const int MOD =1e9 + 7;
//
int n, mod;
int f[N];
//
inline void solve(ll res = 0, ll ans = 0) {
    
    
	for(int i = 1; i <= n; ++ i) {
    
    
		ans = 1ll * f[i] * f[n - i + 1] % mod;
		res = (res + (n - i + 1ll) * ans % mod) % mod;
	}
	cout << (res + mod) % mod << endl;
}
int main() {
    
    
	cin >> n >> mod;
	f[0] = 1;
	for(int i = 1; i <= n; ++ i) {
    
    
		f[i] = 1ll * f[i - 1] * i % mod;
	} 
	solve();
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/qq_46173805/article/details/114269426