数 学 函数
gcd
int gcd(int a,int b){while(a%b){int c=a%b;a=b;b=c;}return b;
}
错位排列
typedef long long ll;
ll d(int n){if(n==1) return 0;if(n==2) return 1;return (n-1)*(d(n-1)+d(n-2));
}
快速幂
//注意看是否有mod的需求
int q_pow(int a,int b){int ans=1,temp=a;while(b){if(b&1) ans=ans*temp;temp=temp*temp;b>>=1;}return ans;
}
组合数
int c(int a,int b){if(a<0||b>a) return 0;if(a==b) return 1;return c(a-1,b)+c(a-1,b-1);
}//优化
#define int long longint n, m, c;
const int MAX_N = 1e7 + 10;// 动态规划计算组合数 C(n, m) mod c
int comb(int n, int m, int mod) {if (m > n) return 0;if (m == 0 || m == n) return 1;// 使用滚动数组优化空间vector<int> dp(m + 1, 0);dp[0] = 1;for (int i = 1; i <= n; ++i) {for (int j = min(i, m); j > 0; --j) {dp[j] = (dp[j] + dp[j - 1]) % mod;}}return dp[m];
}signed main() {cin >> n >> m >> c;cout << comb(n, m, c) << endl;return 0;
}