Lucas的裸题,学习一个。

#include<bits/stdc++.h>
#define N 100010
using namespace std;
typedef long long ll;
ll a[N];
int p;
ll pow(ll y,int z,int p){
y%=p;ll ans=;
for(int i=z;i;i>>=,y=y*y%p)if(i&)ans=ans*y%p;
return ans;
}
ll C(ll n,ll m){
if(m>n)return ;
return ((a[n]*pow(a[m],p-,p))%p*pow(a[n-m],p-,p)%p);
}
ll Lucas(ll n,ll m){
if(!m)return ;
return C(n%p,m%p)*Lucas(n/p,m/p)%p;
}
inline int read(){
int f=,x=;char ch;
do{ch=getchar();if(ch=='-')f=-;}while(ch<''||ch>'');
do{x=x*+ch-'';ch=getchar();}while(ch>=''&&ch<='');
return f*x;
}
int main(){
int T=read();
while(T--){
int n=read(),m=read();p=read();
a[]=;
for(int i=;i<=p;i++)a[i]=(a[i-]*i)%p;
cout<<Lucas(n+m,n)<<endl;
}
}

【HDU3037】Saving Beans的更多相关文章

  1. 【HDOJ】【3037】Saving Beans

    排列组合 啊……这题是要求c(n-1,0)+c(n,1)+c(n+1,2)+......+c(n+m-1,m) 这个玩意……其实就等于c(n+m,m) 好吧然后就是模P……Lucas大法好= = 我S ...

  2. 【HDU 3037】Saving Beans(卢卡斯模板)

    Problem Description Although winter is far away, squirrels have to work day and night to save beans. ...

  3. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  4. 【HDOJ】2430 Beans

    这题目用线段树超时了,其实也差不多应该超时.10^6大数据量.看了一下网上的解法是单调队列.大概了解了一下,是个挺有意思的数据结构.首先,需要求满足0<=(S[r]-S[l])%p<=k时 ...

  5. Solution -「Hdu3037」Saving Beans

    Prob. 给定 \(m\) 个相同球,\(n\) 个不同的盒子. 求在这 \(n\) 个盒子中放不超过 \(m\) 个球的方案数,并对 \(p\) 取模. 其中 \(1 \leq n, m \leq ...

  6. 【解决方案】 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userHandler': Injection of resource dependencies failed;

    一个错误会浪费好多青春绳命 鉴于此,为了不让大家也走弯路,分享解决方案. [错误代码提示] StandardWrapper.Throwableorg.springframework.beans.fac ...

  7. hdu3037 Saving Beans(Lucas定理)

    hdu3037 Saving Beans 题意:n个不同的盒子,每个盒子里放一些球(可不放),总球数<=m,求方案数. $1<=n,m<=1e9,1<p<1e5,p∈pr ...

  8. hdu3037 Saving Beans

    Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Pro ...

  9. HDOJ 3037 Saving Beans

    如果您有n+1树,文章n+1埋不足一棵树m种子,法国隔C[n+m][m] 大量的组合,以取mod使用Lucas定理: Lucas(n,m,p) = C[n%p][m%p] × Lucas(n/p,m/ ...

随机推荐

  1. hdu5575 Discover Water Tank

    题意: 给出个水箱,水箱两侧有无限高的隔板,水箱内有整数高度的隔板将水箱分成n-1份,现在给出m个限制,每个限制表示某个位置的某个高度有水或没水,问最多能同时满足多少个限制.n,m<=2*10^ ...

  2. [SDOI2013]淘金 数位DP

    做了好久.... 大致思路: 求出前k大的方格之和即为答案, 先考虑一维的情况,设f[i]为数位上各个数相乘为i的数的总数,也就是对于数i,有f[i]个数它们各个位相乘为i, 再拓展到二维,根据乘法原 ...

  3. BZOJ3223:文艺平衡树——超详细题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=3223 题面复制于洛谷. 题目背景 这是一道经典的Splay模板题——文艺平衡树. 题目描述 您需要写 ...

  4. cdh版本的sqoop安装以及配置

    sqoop安装需要提前安装好sqoop依赖:hadoop .hive.hbase.zookeeper hadoop安装步骤请访问:http://www.cnblogs.com/xningge/arti ...

  5. [Leetcode] Binary tree postorder traversal二叉树后序遍历

    Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary t ...

  6. POI 2018.10.21

    [POI2008]TRO-Triangles https://www.cnblogs.com/GXZlegend/p/7509699.html 平面上有N个点. 求出所有以这N个点为顶点的三角形的面积 ...

  7. nfs挂载权限问题

    问题: 服务器A:192.168.10.230 服务器B:192.168.10.231 由于服务器A空间不足,打算将服务器A产生的数据库日志挂载到服务器B上,刚开始设定的anonuid和anongid ...

  8. 学习tcpIp必备的抓包工具wireshark

    wireshark是一个优秀的抓包工具 ip.src=192.168.10.123  发送http的一端 ip.dst=192.168.10.126 接收http的一端 如下图所示:

  9. mysql的select的五子句

    转: http://www.cnblogs.com/billyu/p/5033167.html http://www.cnblogs.com/xiadong90-2015/p/4222965.html ...

  10. [iptables]iptables日志记录

    Mar :: kernel: [:] IN=eth1 OUT= MAC=f0:1f:af:da:6f:1e::fb::ae:fa::: SRC= TOS= ID= DF PROTO=TCP SPT= ...