#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>PII;
const double eps=1e-5;
const double pi=acos(-1.0);
//const int mod=1e9+7;
const int INF=0x3f3f3f3f; /*
题意:
求一个组合数,但是要取膜,所以我们要逆元;
思路:
利用费法小定理,就可以啦;
*/
//快速幂;
const LL mod=1000003;
const int N=1e6+10;
LL f[N];
LL cal(LL g,LL x)
{
LL ans=1;
while(g)
{
if(g&1) ans=ans*x%mod;
x=x*x%mod;
g>>=1;
}
return ans;
} //C(N,M)=N!/(M!*(N-M)!);
//这里要取膜,所以要逆元(除法不适用于取膜);
//这里因为mod是质数,所以利用费马小定理就好了///
void solve(LL n,LL m)
{
printf("%lld\n",f[n]*cal(mod-2,f[n-m])%mod*cal(mod-2,f[m])%mod);
}
//预处理一个阶乘数组;
void init()
{
f[0]=1;
for(LL i=1;i<=1000000;i++)
f[i]=f[i-1]*i%mod;
} int main()
{
init();
int T,cas=1;
scanf("%d",&T);
while(T--)
{
LL n,k;
scanf("%lld%lld",&n,&k);
printf("Case %d: ",cas++);
solve(n,k);
}
return 0;
}

Lightoj 1067【逆元模板(求C(N,M))】的更多相关文章

  1. 求组合数、求逆元、求阶乘 O(n)

    在O(n)的时间内求组合数.求逆元.求阶乘.·.· #include <iostream> #include <cstdio> #define ll long long ;// ...

  2. YTU 2642: 填空题:类模板---求数组的最大值

    2642: 填空题:类模板---求数组的最大值 时间限制: 1 Sec  内存限制: 128 MB 提交: 646  解决: 446 题目描述   类模板---求数组的最大值    找出一个数组中的元 ...

  3. 线性筛prime/phi/miu/求逆元模板

    这绿题贼水...... 原理我不讲了,随便拿张草稿纸推一下就明白了. #include <cstdio> using namespace std; ; int su[N],ans,top; ...

  4. uva11916 bsgs算法逆元模板,求逆元,组合计数

    其实思维难度不是很大,但是各种处理很麻烦,公式推导到最后就是一个bsgs算法解方程 /* 要给M行N列的网格染色,其中有B个不用染色,其他每个格子涂一种颜色,同一列上下两个格子不能染相同的颜色 涂色方 ...

  5. 【codevs 1200】【NOIP 2012】同余方程 拓展欧几里德求乘法逆元模板题

    模板,,, #include<cstdio> using namespace std; void exgcd(long long a,long long b,long long & ...

  6. HDU - 5651 xiaoxin juju needs help 逆元模板

    http://acm.hdu.edu.cn/showproblem.php?pid=5651 题意:生成回文串.输出所有回文串的可能数. 题解:mod除法会损失高位,用逆元来代替除法,模板如下 ac代 ...

  7. 牛客多校第六场 C Generation I 组合数学 阶乘逆元模板

    链接:https://www.nowcoder.com/acm/contest/144/C来源:牛客网 Oak is given N empty and non-repeatable sets whi ...

  8. AtCoder Beginner Contest 142【D题】【判断素数的模板+求一个数的因子的模板】

    D - Disjoint Set of Common Divisors Problem Statement Given are positive integers AA and BB. Let us ...

  9. poj 2187 Beauty Contest 凸包模板+求最远点对

    题目链接 题意:给你n个点的坐标,n<=50000,求最远点对 #include <iostream> #include <cstdio> #include <cs ...

随机推荐

  1. 几个经典的TCP通信函数

    前言 在TCP通信中要使用到几个非常经典的函数( 点这里参考一个关于它们作用的形象比方 ),本文将对这几个函数进行一个简短的使用说明. socket函数 函数作用:创建一个网际字节流套接字 包含头文件 ...

  2. 对ShortCut和TWMKey的研究

    TWMKey = packed record Msg: Cardinal; CharCode: Word; Unused: Word; KeyData: Longint; Result: Longin ...

  3. mysql给一张表新增字段,并设置该字段为外键

    首先给usercategory表新增libraryid字段: alter table usercategory add libraryid varchar(50) 修改picturelibrary表的 ...

  4. pyinstaller-py2exe-cx_Freeze打包第一个wxPython程序HelloWorld

    pyinstaller 打包hello 7Mb ================= www.pyinstaller.org pip install pypiwin32 pip install pyin ...

  5. ZOJ - 3935 2016 【数的筛选】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3935 题意 要求找出 从 2016-990528 中 是闰年 并 ...

  6. php获取accesstoken和二维码的实现方法

    class WeChat{ private $_appid; private $_appsecret; private $_token; public function __construct($_a ...

  7. -webkit-mask-box-image给框架加个同样大小的遮罩

    很棒的css属性,可以在div上方建个同大小的遮罩,配合线性变化gradient可以实现很酷的样式,比如:时间选择的UI组件,里面有个模糊的上方遮罩 手册地址:https://developer.mo ...

  8. 人生苦短之Python多线程

    #encoding=utf-8 import threading import time ''' python多线程并不是真正意义上的多线程,通常我们所说的多线程是多个线程同时执行某功能,而在pyth ...

  9. 内部类访问外部类方法中的参数-使用final

    public synchronized <T extends MetricsSource> T register(final String name, final String desc, ...

  10. Linux下监控网卡流量的软件iftop

    官网上说使用iftop需要libpcap和libcurses这两个包. 用命令查找了一下 #  rpm -qa | grep libpcap libpcap-0.9.4-15.el5 只找到了这个,缺 ...