题解来咯
2026-07-29 22:52:57
发布于:广东
24阅读
0回复
0点赞
**题解!!!一个赞,一个罐头
#include <bits/stdc++.h> //万能头文件
using namespace std;
const int MOD=1e9+7; //取模常数
long long qpow(long long a,long long b){ //快速幂求逆元
long long res=1; //结果初始化为1
while(b){ //指数大于0时循环
if(b%2==1){ //如果当前二进制位是1
res=res*a%MOD; //乘上当前底数
}
a=a*a%MOD; //底数平方
b=b/2; //指数右移一位
}
return res; //返回结果
}
long long C(int x,int y){ //求组合数C(x,y)
if(y<0||y>x){ //如果y不合法
return 0; //返回0
}
long long ans=1; //答案初始化为1
for(int i=1;i<=y;i++){ //从1到y循环
ans=ans*(x-y+i)%MOD; //乘上分子部分
ans=ans*qpow(i,MOD-2)%MOD; //乘上i的逆元(除以i)
}
return ans; //返回组合数
}
int main(){
ios::sync_with_stdio(false); //加速输入输出
cin.tie(nullptr); //取消cin和cout的绑定
int m,n; //定义m和n
cin>>m>>n; //读入m和n
cout<<C(n-1,m-1); //输出C(n-1,m-1)
return 0; //返回0
}
**
纯代码
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
long long qpow(long long a,long long b){
long long res=1;
while(b){
if(b%2==1){
res=res*a%MOD;
}
a=a*a%MOD;
b=b/2;
}
return res;
}
long long C(int x,int y){
if(y<0||y>x){
return 0;
}
long long ans=1;
for(int i=1;i<=y;i++){
ans=ans*(x-y+i)%MOD;
ans=ans*qpow(i,MOD-2)%MOD;
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int m,n;
cin>>m>>n;
cout<<C(n-1,m-1);
return 0;
}
👍666

这里空空如也








有帮助,赞一个