http://codeforces.com/gym/100633/problem/J


Lucas定理P不是质数裸题

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
inline ll read(){
char c=getchar();ll x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
} ll n,m,MOD;
ll Pow(ll a,ll b,ll P){
ll ans=;
for(;b;b>>=,a=a*a%P)
if(b&) ans=ans*a%P;
return ans;
}
void exgcd(ll a,ll b,ll &d,ll &x,ll &y){
if(b==) d=a,x=,y=;
else exgcd(b,a%b,d,y,x),y-=(a/b)*x;
}
ll Inv(ll a,ll n){
ll d,x,y;
exgcd(a,n,d,x,y);
return d==?(x+n)%n:-;
}
ll Fac(ll n,ll p,ll pr){
if(n==) return ;
ll re=;
for(ll i=;i<=pr;i++) if(i%p) re=re*i%pr;
re=Pow(re,n/pr,pr);
ll r=n%pr;
for(int i=;i<=r;i++) if(i%p) re=re*i%pr;
return re*Fac(n/p,p,pr)%pr;
}
ll C(ll n,ll m,ll p,ll pr){
if(n<m) return ;
ll x=Fac(n,p,pr),y=Fac(m,p,pr),z=Fac(n-m,p,pr);
ll c=;
for(ll i=n;i;i/=p) c+=i/p;
for(ll i=m;i;i/=p) c-=i/p;
for(ll i=n-m;i;i/=p) c-=i/p;
ll a=x*Inv(y,pr)%pr*Inv(z,pr)%pr*Pow(p,c,pr)%pr;
return a*(MOD/pr)%MOD*Inv(MOD/pr,pr)%MOD;
} ll Lucas(ll n,ll m){
ll x=MOD,re=;
for(ll i=;i<=MOD;i++) if(x%i==){
ll pr=;
while(x%i==) x/=i,pr*=i;
re=(re+C(n,m,i,pr))%MOD;
}
return re;
}
int main(){
//freopen("in","r",stdin);
n=read();m=read();MOD=read();
printf("%I64d",Lucas(n,m));
}

CF 2015 ICL, Finals, Div. 1 J. Ceizenpok’s formula [Lucas定理]的更多相关文章

  1. codeforces2015ICL,Finals,Div.1#J Ceizenpok’s formula【扩展lucas】

    传送门 [题意]: 求C(n,k)%m,n<=108,k<=n,m<=106 [思路]: 扩展lucas定理+中国剩余定理    #include<cstdio> usi ...

  2. codeforces2015ICL,Finals,Div.1#J Ceizenpok’s formula 扩展Lucas定理 扩展CRT

    默默敲了一个下午,终于过了, 题目传送门 扩展Lucas是什么,就是对于模数p,p不是质数,但是不大,如果是1e9这种大数,可能没办法, 对于1000000之内的数是可以轻松解决的. 题解传送门 代码 ...

  3. 2015 ICL, Finals, Div. 1 Ceizenpok’s formula(组合数取模,扩展lucas定理)

    J. Ceizenpok’s formula time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  4. 2015 ICL, Finals, Div. 2【ABFGJK】

    [题外话:我......不补了......] 2015 ICL, Finals, Div. 2:http://codeforces.com/gym/100637 G. #TheDress[水] (st ...

  5. GYM100633J. Ceizenpok’s formula 扩展lucas模板

    J. Ceizenpok’s formula time limit per test 2.0 s memory limit per test 256 MB input standard input o ...

  6. Ceizenpok’s formula Gym - 100633J 扩展Lucas定理 + 中国剩余定理

    http://codeforces.com/gym/100633/problem/J 其实这个解法不难学的,不需要太多的数学.但是证明的话,我可能给不了严格的证明.可以看看这篇文章 http://ww ...

  7. CF Codeforces Round #231 (Div. 2)

    http://codeforces.com/contest/394 话说这次CF做的超级不爽,A题一开始交过了,我就没再管,B题还没看完呢,就死困死困的,后来觉得B题枚举一下估计能行,当时是觉得可以从 ...

  8. [cf]Codeforces Round #784(Div 4)

    由于一次比赛被虐得太惨,,生发开始写blog的想法,于是便有了这篇随笔(找了个近期的cf比赛练练手(bushi))第一次写blog,多多包涵. 第二场cf比赛,第一场打的Div2,被虐太惨,所以第二场 ...

  9. 2015弱校联盟(2) - J. Usoperanto

    J. Usoperanto Time Limit: 8000ms Memory Limit: 256000KB Usoperanto is an artificial spoken language ...

随机推荐

  1. timeit模块

    算法是计算机处理信息的本质,因为计算机程序本质上是一个算法来告诉计算机确切的步骤来执行一个指定的任务.一般地,当算法在处理信息时,会从输入设备或数据的存储地址读取数据,把结果写入输出设备或某个存储地址 ...

  2. JS URI Encode

    javascript中存在几种对URL字符串进行编码的方法:escape/encodeURI/encodeURIComponent.这几种编码所起的作用各不相同. escape 采用ISO Latin ...

  3. IDEA安装vue开发插件

    前言: 开发免不了要用到开发工具,什么sublime,webstorm,idea的,现在我就说下idea开发神器下安装vue插件进行vue项目的开发吧. idea下载地址:http://www.jet ...

  4. The most interesting feature of iPhone X - FaceID

    No doubt everybody knows that iPhone 8 & iPhone X appear on the market. A feature called FaceID ...

  5. HttpServletRequest cannot be resolved to a type。

    问题描述:HttpServletRequest cannot be resolved to a type.Multiple markers at this line - The import java ...

  6. linux 动态库的符号冲突问题

    最近,给同事定位了一个符号表的冲突问题,简单记录一下. A代码作为静态链接库,被包含进了B代码,然后编译成了动态链接库,B.so A代码同时作为静态链接库,被编译进入了main的主代码. main函数 ...

  7. Linux Server release 7.3 更换阿里网络yum源

    查看当前系统下的yum源 [root@localhost ~]# rpm -qa |grep yum yum-3.4.3-150.el7.noarch yum-utils-1.1.31-40.el7. ...

  8. mysql-innoDB-多版本并发控制(MVCC)

    InnoDB的MVCC,是通过在每行记录后面保存三个隐藏的列来实现的其中的两个列一个保存了行的创建时间,一个保存行的过期时间(或删除时间).当然存储的并不是实际的时间值,而是系统版本号(system ...

  9. linkin大话面向对象--枚举

    枚举类(enum) 其实我们使用到枚举的地方还是很多的,其实我们可以完全人工的来实现枚举的功能.比如说我现在手里的项目我就是自己实现的枚举,说白了,枚举就是一个类的多例模式. 1,使用enum声明,默 ...

  10. Myeclipse 10安装与破解

    首先下载Myeclipse 10的压缩包,我这里以10.7版本为例.下载路径分享 链接:https://pan.baidu.com/s/1nxf19S9 密码:rqw4 下载好后解压,解压后进行安装. ...