hdu3037 lucas 定理 组合数取模

#include<stdio.h>
#include<string>
#include<map>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
#define rep0(i,n) for(int i=0;i<n;i++)
#define rep(i,j,k) for(int i=j;i<k;i++)
const int N=1e5+10;
const int MOD=1e9+7;
int n,m,k,up,p;
int A[N];
int inv[N];
long long qmod(long long  a,long long b){
    long long res=1;
    while(b){
       if(b&1) res=res*a%p;
        a=a*a%p;
        b>>=1;
    }
    return res;
}
int get(int a,int b){
    long long n=1,m=1;
    while(b){
        n=n*a%p;
        m=m*b%p;
        a--,b--;
    }
    return n*qmod(m,p-2)%p;
}
int solve(int a,int b){
    long long  res=1;
    while(b){
        res=res*get(a%p,b%p)%p;
        a/=p;b/=p;
    }
    return res;
}
int main(){
#ifndef ONLINE_JUDGE
  freopen("aaa","r",stdin);
#endif
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%d%d%d",&n,&m,&p);
        int a=n+m;
        int b=n;
        printf("%d\n",solve(a,b));
    }
    return 0;
}

你可能感兴趣的:(hdu3037 lucas 定理 组合数取模)