链接
https://codeforces.com/contest/1284/problem/C
题意
对于一个有 个不重复数的序列的排列中有多少个区间使
思路
假设 满足上述等式,设 ,对于此区间,其所有排列均满足上述等式,即有 种排列
将此区间看成一个数放入原序列,则原序列中有 个数,有 种排列
而对于区间长度 满足 的共有 种情况
所以对于区间长度 共有 , 即可算出结果
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=250005; int n,m; ll fac[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>m; fac[1]=1; for(int i=2;i<=n;i++) fac[i]=fac[i-1]*i%m; ll ans=0; for(int i=1;i<=n;i++) ans=(ans+fac[i]*fac[n-i+1]%m*(n-i+1)%m)%m; cout<<ans<<endl; return 0; }
|
来做第一个留言的人吧!