Codeforces Round #181 (Div. 2)C
用lucas定理, p必须是素数
对于单独的C(n, m) mod p,已知C(n, m) mod p = n!/(m!(n - m)!) mod p。显然除法取模,这里要用到m!(n-m)!的逆元。
根据费马小定理:
已知(a, p) = 1,则 ap-1 ≡ 1 (mod p), 所以 a*ap-2 ≡ 1 (mod p)。
也就是 (m!(n-m)!)的逆元为 (m!(n-m)!)p-2 ;
所以C(n, m) mod p = n! * (m! * (n - m)! )^(p-2)%mod
中间用快速幂取余
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f; ll fac[N],a,b;
bool ok(ll x)
{
while(x){
if(x%!=a&&x%!=b)return ;
x/=;
}
return ;
}
ll quick(ll a,ll b)
{
ll ans=;
while(b){
if(b&)ans=ans*a%mod;
a=a*a%mod;
b/=;
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
fac[]=fac[]=;
for(ll i=;i<N;i++)
fac[i]=fac[i-]*i%mod;
ll n,ans=;
cin>>a>>b>>n;
for(ll i=;i<=n;i++)
if(ok(a*i+(n-i)*b))
ans=(ans+fac[n]*quick(fac[i]*fac[n-i]%mod,mod-)%mod)%mod;
cout<<ans<<endl;
return ;
}
/******************** ********************/
Codeforces Round #181 (Div. 2)C的更多相关文章
- Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力
C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...
- Codeforces Round #181 (Div. 2) B. Coach 带权并查集
B. Coach 题目连接: http://www.codeforces.com/contest/300/problem/A Description A programming coach has n ...
- Codeforces Round #181 (Div. 2) A. Array 构造
A. Array 题目连接: http://www.codeforces.com/contest/300/problem/A Description Vitaly has an array of n ...
- Codeforces Round #181 (Div. 2)
A. Array 模拟. B. Coach 模拟. C. Beautiful Numbers good number的位和最大不超过\(10^7\),那么只要枚举a或b的个数,然后最多循环7次判断位和 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
随机推荐
- 在Mac OS X使用Elasticsearch的基本流程
这篇日志的目的非常easy,就是记录一些主要的流程.要在OS X上使用Elasticsearch,事实上非常easy,在这里:https://www.elastic.co/downloads/elas ...
- DotNetBar.Bar图标列表的使用
DotNetBar.Bar图标列表的使用 老帅 控件DevComponents.DotNetBar.Bar怎样使用图像列表呢?比方给工具条或者菜单加上图标.例如以下几步就可以! 方法1: 1.放一个S ...
- 升级系统到ubuntun到18.04后apt-get执行失败
系统升级到18.04后执行apt-get install的时候报错 root@zhf-maple:/home/zhf/桌面# apt-get install vim-sciptsE: 无法获得锁 /v ...
- 006-shiro授权
一.授权流程 二.三种授权方式 2.1.编程式:通过写if/else 授权代码块完成: Subject subject = SecurityUtils.getSubject(); if(subject ...
- java开发的zimg客户端
1.zimg的安装部署 最开始的时候是下载zimg的源码安装的,由于zimg依赖项众多,没有安装成功,刚好那期间在学习docker,于是docker search zimg一下,惊奇的发现有zimg镜 ...
- 重置Linux普通账号和root账号密码
今天想在Linux测试下HTTPie, 突然发现虚拟机里面的Linux, root账号和普通账号密码都忘记了. 百度了半天发现答案都不对, 最后用Google搜到了答案. 本人系统环境: VMware ...
- go——函数
1.定义 函数是结构化编程的最小单元模式.它将复杂的算法过程分解为若干个较小任务,隐藏相关细节,使程序结构更加清晰,易于维护.函数被设计成相对独立,通过接收输入参数完成一段算法指令,输出或存储相关结果 ...
- xpath中遇到[<Element a at 0x39a9a80>](转)
Element是什么 回归正题,大家晕头转脑的看完繁杂的语法之后,已经迫不及待写点什么东西了,然后部分同学可能遇到了这个 <Element a at 0x39a9a80>或者类似 Elem ...
- HDU - 1695 GCD (容斥+枚举)
题意:求区间1<=i<=b与区间1<=j<=d之间满足gcd(i,j) = k 的数对 (i,j) 个数.(i,j)与(j,i) 算一个. 分析:gcd(i,j)=k可以转化为 ...
- $python正则表达式系列(3)——正则内置属性
本文主要总结一下python正则的一些内置属性的用法. 1. 编译标志:flags 首先来看一下re.findall函数的函数原型: import re print('[Output]') print ...