Lightoj 1067【逆元模板(求C(N,M))】
#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))】的更多相关文章
- 求组合数、求逆元、求阶乘 O(n)
在O(n)的时间内求组合数.求逆元.求阶乘.·.· #include <iostream> #include <cstdio> #define ll long long ;// ...
- YTU 2642: 填空题:类模板---求数组的最大值
2642: 填空题:类模板---求数组的最大值 时间限制: 1 Sec 内存限制: 128 MB 提交: 646 解决: 446 题目描述 类模板---求数组的最大值 找出一个数组中的元 ...
- 线性筛prime/phi/miu/求逆元模板
这绿题贼水...... 原理我不讲了,随便拿张草稿纸推一下就明白了. #include <cstdio> using namespace std; ; int su[N],ans,top; ...
- uva11916 bsgs算法逆元模板,求逆元,组合计数
其实思维难度不是很大,但是各种处理很麻烦,公式推导到最后就是一个bsgs算法解方程 /* 要给M行N列的网格染色,其中有B个不用染色,其他每个格子涂一种颜色,同一列上下两个格子不能染相同的颜色 涂色方 ...
- 【codevs 1200】【NOIP 2012】同余方程 拓展欧几里德求乘法逆元模板题
模板,,, #include<cstdio> using namespace std; void exgcd(long long a,long long b,long long & ...
- HDU - 5651 xiaoxin juju needs help 逆元模板
http://acm.hdu.edu.cn/showproblem.php?pid=5651 题意:生成回文串.输出所有回文串的可能数. 题解:mod除法会损失高位,用逆元来代替除法,模板如下 ac代 ...
- 牛客多校第六场 C Generation I 组合数学 阶乘逆元模板
链接:https://www.nowcoder.com/acm/contest/144/C来源:牛客网 Oak is given N empty and non-repeatable sets whi ...
- AtCoder Beginner Contest 142【D题】【判断素数的模板+求一个数的因子的模板】
D - Disjoint Set of Common Divisors Problem Statement Given are positive integers AA and BB. Let us ...
- poj 2187 Beauty Contest 凸包模板+求最远点对
题目链接 题意:给你n个点的坐标,n<=50000,求最远点对 #include <iostream> #include <cstdio> #include <cs ...
随机推荐
- centos6.4中文输入法安装和切换(转载)
1.用root登录,或者切换到root账户(su root): 2.yum install "@Chinese Support"; 3.exit: 4.System→prefere ...
- duplicate symbols for architeture arm64 linker command failed with code 1(use-c to see invocation)
duplicate symbols for architeture arm64 linker command failed with code 1(use-c to see invocation) ...
- 2016/07/07 apmserv5.2.6 Apache启动失败,请检查相关配置。MySQL5.1已启动。
因为要用PHP做一个程序,在本机上配PHP环境,下了个APMServ5.26,安装很简单,不再多说,装好后,启动,提示错误,具体是:“Apache启动失败,请检查相关配置.√MySQL5.1已启动”, ...
- EasyRTMP手机直播推送rtmp流flash无法正常播放问题
本文转自EasyDarwin团队Kim的博客:http://blog.csdn.net/jinlong0603/article/details/52960750 问题简介 EasyRTMP是EasyD ...
- Consul环境搭建
大家在玩的时候 一定要使用ningx 1.9以上版本啊! 下载:wget https://releases.hashicorp.com/consul/0.7.5/consul_0.7.5_linux_ ...
- python生成图片
# -*- coding:utf-8 -*- from pylab import * figure(1,figsize=(6,6)) ax = axes([0.1,0.1,0.8,0.8]) frac ...
- ansible j2文件注意事项
j2文件中使用变量的时候,不需要 {{}} 遇到if,for等条件判断语句,变量的话,只需要变量名即可, 字符串需要 加上引号.
- Tensorflow深度学习之十二:基础图像处理之二
Tensorflow深度学习之十二:基础图像处理之二 from:https://blog.csdn.net/davincil/article/details/76598474 首先放出原始图像: ...
- hdu-5761 Rower Bo(数学)
题目链接: Rower Bo Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- Python:条件判断
条件控制:if...elif...else if condition_1: statement_1 elif condition_2: statement_2 else: statement_3 判断 ...