一次询问
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll work(int n,int m){
if(m>n/2) m = n-m;
ll a = 1,b = 1;
for(int i=1;i<=m;i++){
a*=n+1-i;
b*=i;
if(a%b==0) a/=b,b=1;
}
return a/b;
}
int main(){
int n,m;
scanf("%d %d",&n,&m);//49 6
printf("%lld\n",work(n,m));//13983816
return 0;
}
多次询问
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll c[105][105];
void pp(){
for(int i=0;i<102;i++) c[i][0]=1;
for(int i=1;i<101;i++)
for(int j=1;j<101;j++)
c[i][j]=c[i-1][j] + c[i-1][j-1];
}
int main(){
pp();
int n,m;
while(~scanf("%d %d",&n,&m) && (n||m)){//100 6
printf("C(%d,%d) = %lld",n,m,c[n][m]);//1192052400
}
return 0;
}