QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#108106 | #5749. Directed Vertex Cacti | Fanch100 | RE | 0ms | 0kb | C++14 | 678b | 2023-05-23 16:28:19 | 2023-05-23 16:28:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 10000010;
int n, m, mod;
ll qpow(ll a,ll b){
ll res=1;
for (; b; b>>=1){
if (b&1) res=res*a%mod;
a=a*a%mod;
}
return res;
}
ll pro[N], inv[N];
void init(){
pro[0]=1;
for (int i=1;i<N;++i) pro[i]=pro[i-1]*i%mod;
inv[N-1]=qpow(pro[N-1],mod-2);
for (int i=N-1;i>=1;--i) inv[i-1]=inv[i]*i%mod;
}
int main(){
cin>>n>>m>>mod;
init();
ll ans=pro[n];
ll tot=1ll*n*(n-1)/2%mod;
for (int i=1;i<=m;++i){
ans=ans*tot%mod; tot--;
}
ans=ans*inv[m]%mod;
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 1