Each test case contains two integers n (1 ≤ n ≤ 106), k (0 ≤ k ≤ n).
Case 3: 15
除法求模不能类似乘法,对于(A/B)mod C,直接(A mod C)/ (B mod C)是错误的;找到B的逆元b(b=B^-1);求出(A*b)modC即可;
由费马小定理:B 关于 P 的逆元为 B^(p-2);
数学排列组合公式:C(n,m)= n!/(m!*(n-m)!)
代码:
#include
#include
#include
using namespace std;
#define LL long long
#define G 1100000
#define mod 1000003
LL pri[G];
LL ni[G],ans;
LL pow(LL a,int b)
{
LL ans=1,base=a;
while (b>0)
{
if (b%2==1)
ans=(base*ans)%mod;
base=(base*base)%mod;
b/=2;
}
return ans;
}
void s() //打表
{
pri[0]=1;
ni[0]=1;
for (int i=1;i