纯粹的lucas定理,因为n,m的数据比较小,所以可以直接用公式:
c(n,m) = ( (a! * ((a-b)!)^(p-2) % mod) * ((b!)^(p-2)) ) % mod;
详见代码:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <cctype>
#include <cmath>
#include <cstring>
#include <climits>
#include <complex>
#include <set>
#include <deque>
#define DEBUG(x) cerr<<"line:"<<__LINE__<<", "<<#x" == "<<(x)<<endl;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(it,s) for(__typeof(s.begin()) it=s.begin();it!=s.end();it++)
#define ALL(a) a.begin(),a.end()
#define RI(x) scanf("%d",&(x))
#define RII(x,y) scanf("%d%d",&(x),&(y))
#define RIII(x,y,z) scanf("%d%d%d",&(x),&(y),&(z))
#define DRI(x) int (x);scanf("%d",&(x))
#define DRII(x,y) int (x),(y);scanf("%d%d",&(x),&(y))
#define DRIII(x,y,z) int (x),(y),(z);scanf("%d%d%d",&(x),&(y),&(z))
#define MS0(a) memset((a),0,sizeof((a)))
#define MS1(a) memset((a),-1,sizeof((a)))
#define MS(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;
#define INF 1000000000
const double eps = 1e-10;
int dcmp(double x){
if(fabs(x) < eps) return 0;
else return x < 0 ? -1 : 1;
}
// ------------------
// author : onehrxn
// ------------------
const LL mod = 1000003;
const int maxn = 1000000+10;
LL fac[maxn];
void init(void){
fac[1] = fac[0] = 1;
for(int i = 2; i <= maxn - 2; i++) fac[i] = fac[i-1]*i % mod;
}
LL qpow(LL a, LL b){
LL ans;
for(ans = 1; b ; b >>= 1, a = (a * a) % mod)
if(b & 1) ans = (ans * a) % mod;
return ans;
}
inline LL lucas(LL a, LL b, LL p){
return (((fac[a] * qpow(fac[b],p-2))%mod) * qpow(fac[a-b],p-2) )% mod;
}
int main(void)
{
// ios::sync_with_stdio(false);
// cin.tie(0);
#ifdef LOCAL
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
#endif
init();
DRI(t);
for(int kase = 1; kase <= t; kase++){
DRII(n,k);
printf("Case %d: %lld\n", kase, lucas(n,k,mod));
}
#ifdef LOCAL
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}