【loj6142】「2017 山东三轮集训 Day6」A 结论题+Lucas定理
题解:
当奇数
发现答案就是C(n,1)^2+C(n,3)^2+。。。C(n,n)^2
倒序相加,发现就是C(2n,n) 所以答案就是C(2n,n)/2
当偶数
好像并不会证
打表出来可以得到
2.当n为偶数且为4的倍数时,答案为C(2n,n)+C(n,n/2)/2
3.当n为偶数且不为4的倍数时,答案为C(2n,n)-C(n,n/2)/2
另外Claris告诉我在p较小时可以数位dp来求
先用lucas定理 C(n,m)=C(n%p,m%p)*C(n/p,m/p)
然后我们就可以把n表示成p进制
答案就是m在p进制下和对应n求C的乘积
然后我们可以数位dp这个东西
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define rint register ll
- #define IL inline
- #define rep(i,h,t) for (rint i=h;i<=t;i++)
- #define dep(i,t,h) for (rint i=t;i>=h;i--)
- const ll p=
- ;
- const ll mo=
- ;
- const ll INF=1e18;
- const ll N=2e6;
- ll n,cnt=,a[],jc1[N],jc2[N],f[N][][];
- void gcd(ll x,ll y,ll &a,ll &b)
- {
- if (y==)
- {
- a=; b=; return;
- }
- gcd(y,x%y,b,a);
- b-=a*(x/y);
- }
- ll C(ll x,ll y)
- {
- if (x<y) return();
- return jc1[x]*jc2[y]%p*jc2[x-y]%p;
- }
- void jf(ll &x,ll y)
- {
- x+=y;
- if (x>p) x-=p;
- }
- int main()
- {
- cin>>n;
- while (n) a[++cnt]=n%p,n/=p;
- jc1[]=jc2[]=;
- rep(i,,p)
- {
- jc1[i]=(jc1[i-]*i)%p;
- jc1[i]=(jc1[i]+p)%p;
- ll x,y;
- gcd(i,p,x,y);
- jc2[i]=(jc2[i-]*x)%p;
- jc2[i]=(jc2[i]+p)%p;
- }
- f[cnt+][][]=;
- dep(j,cnt,)
- {
- ll tmp1j=,tmp1o=;
- rep(i,,a[j]-)
- {
- ll kk=C(a[j],i);
- kk=(kk*kk)%mo;
- if (i%)
- jf(tmp1j,kk);
- else jf(tmp1o,kk);
- }
- f[j][][]=(f[j+][][]*tmp1o%mo+f[j+][][]*tmp1j%mo)%mo;
- f[j][][]=(f[j+][][]*tmp1j%mo+f[j+][][]*tmp1o%mo)%mo;
- if (a[j]%) jf(tmp1j,); else jf(tmp1o,);
- f[j][][]+=(f[j+][][]*tmp1o%mo+f[j+][][]*tmp1j%mo)%mo;
- f[j][][]+=(f[j+][][]*tmp1j%mo+f[j+][][]*tmp1o%mo)%mo;
- if (f[j+][][]) f[j][(+a[j])%][]=;
- else f[j][a[j]%][]=;
- }
- ll ans=(f[][][]+f[][][])%mo;
- cout<<ans<<endl;
- }
【loj6142】「2017 山东三轮集训 Day6」A 结论题+Lucas定理的更多相关文章
- Loj #6142. 「2017 山东三轮集训 Day6」A
link: https://loj.ac/problem/6142 推完一波式子之后发现求的是:ΣC(N,i)^2, 其中i是偶数. 然后就可以卢卡斯乱搞了,分奇偶和之前的答案合并就好了233. #i ...
- 「2017 山东三轮集训 Day1」Flair
模拟赛的题 好神仙啊 题面在这里 之前的Solution很蠢 现在已经update.... 题意 有$ n$个商品价格均为$ 1$,您有$ m$种面值的货币,面值为$ C_1..C_m$ 每种物品你有 ...
- 【loj6145】「2017 山东三轮集训 Day7」Easy 动态点分治+线段树
题目描述 给你一棵 $n$ 个点的树,边有边权.$m$ 次询问,每次给出 $l$ .$r$ .$x$ ,求 $\text{Min}_{i=l}^r\text{dis}(i,x)$ . $n,m\le ...
- loj #6138. 「2017 山东三轮集训 Day4」Right
题目: 题解: 暴力一波 \(SG\) 函数可以发现这么一个规律: \(p\) 为奇数的时候 : \(SG(n) = n \% 2\) \(p\) 为偶数的时候 : \(SG(n) = n \% (p ...
- loj #6136. 「2017 山东三轮集训 Day4」Left
题目: 题解: 我们可以发现所有的交换器都是一个位置连接着下一层左侧的排序网络,另一个位置连着另一侧的排序网络. 而下一层是由两个更低阶的排序网络构成的. 两个网络互不干扰.所以我们可以通过第一行和最 ...
- 「2017 山东三轮集训 Day7」Easy
一棵带边权的树,多次询问 $x$ 到编号为 $[l,r]$ 的点最短距离是多少 $n \leq 100000$ sol: 动态点分治,每层重心维护到所有点的距离 查询的时候在管辖这个点的 log 层线 ...
- #6145. 「2017 山东三轮集训 Day7」Easy 动态点分治
\(\color{#0066ff}{题目描述}\) JOHNKRAM 最近在参加 C_SUNSHINE 举办的聚会. C 国一共有 n 座城市,这些城市由 n−1 条无向道路连接.任意两座城市之间有且 ...
- LOJ #6145. 「2017 山东三轮集训 Day7」Easy 点分树+线段树
这个就比较简单了~ Code: #include <cstdio> #include <algorithm> #define N 100004 #define inf 1000 ...
- 「2017 山东三轮集训 Day7 解题报告
「2017 山东三轮集训 Day7」Easy 练习一下动态点分 每个点开一个线段树维护子树到它的距离 然后随便查询一下就可以了 注意线段树开大点... Code: #include <cstdi ...
随机推荐
- QT 开发小记
1.开发socket网络通信时,需要在.pro 文件中添加 network项 QT += network 2. 报错: mutilple definition of 时,查看 .pro ...
- Qt5全局热键第三方库qxtglobalshortcut5使用
1.下载第三方库https://github.com/ddqd/qxtglobalshortcut5. 2.把qxtglobalshortcut5文件放在项目目录下,在项目.pro加入一句,inclu ...
- python操作三大主流数据库(10)python操作mongodb数据库④mongodb新闻项目实战
python操作mongodb数据库④mongodb新闻项目实战 参考文档:http://flask-mongoengine.readthedocs.io/en/latest/ 目录: [root@n ...
- 缓存系列之五:通过codis3.2实现redis3.2.8集群的管理
通过codis3.2实现redis3.2.8集群 一:Codis 是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 Codis Proxy 和连接原生的 Redis Server 没 ...
- 配置国内 Docker Registry Mirror
由于国内特殊的网络环境,往往我们从Docker Hub中拉取镜像并不能成功,而且速度特别慢. 那么我们可以给Docker配置一个国内的registry mirror,当我们需要的镜像在mirror中则 ...
- 7-Links
Use the <a> element to define a link Use the href attribute to define the link address Use the ...
- mysql:赋予用户权限、查看及修改端口号
一.mysql 赋给用户权限 grant all privileges on *.* to joe@localhost identified by '1'; flush privileges; 即用u ...
- 【原创】运维基础之Docker(5)docker部署airflow
部署方式:docker+airflow+mysql+LocalExecutor 使用airflow的docker镜像 https://hub.docker.com/r/puckel/docker-ai ...
- mysql修改字段长度及pymysql.err.DataError: (1406, "Data too long for column 'name' at row 1")错误
文章链接:修改字段:https://blog.csdn.net/xiejunna/article/details/78580682 错误分析:https://blog.csdn.net/qq_4214 ...
- python-进程池与线程池,协程
一.进程池与线程池 实现并发的手段有两种,多线程和多进程.注:并发是指多个任务看起来是同时运行的.主要是切换+保存状态. 当我们需要执行的并发任务大于cpu的核数时,我们需要知道一个操作系统不能无限的 ...